lua.c 849 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. ** lua.c
  3. ** Linguagem para Usuarios de Aplicacao
  4. ** TeCGraf - PUC-Rio
  5. ** 28 Apr 93
  6. */
  7. #include <stdio.h>
  8. #include "lua.h"
  9. #include "lualib.h"
  10. void test (void)
  11. {
  12. lua_pushobject(lua_getparam(1));
  13. lua_call ("c", 1);
  14. }
  15. static void callfunc (void)
  16. {
  17. lua_Object obj = lua_getparam (1);
  18. if (lua_isstring(obj)) lua_call(lua_getstring(obj),0);
  19. }
  20. static void execstr (void)
  21. {
  22. lua_Object obj = lua_getparam (1);
  23. if (lua_isstring(obj)) lua_dostring(lua_getstring(obj));
  24. }
  25. int main (int argc, char *argv[])
  26. {
  27. int i;
  28. if (argc < 2)
  29. {
  30. puts ("usage: lua filename [functionnames]");
  31. return;
  32. }
  33. lua_register ("callfunc", callfunc);
  34. lua_register ("execstr", execstr);
  35. lua_register ("test", test);
  36. iolib_open ();
  37. strlib_open ();
  38. mathlib_open ();
  39. lua_dofile (argv[1]);
  40. for (i=2; i<argc; i++)
  41. {
  42. lua_call (argv[i],0);
  43. }
  44. return 0;
  45. }