2 * Example of a C program that interfaces with Lua.
3 * Based on Lua 5.0 code by Pedro Martelletto in November, 2003.
4 * Updated to Lua 5.1. David Manura, January 2007.
6 * L4: Made it just call the interpreter.
16 main(int argc, char **argv)
23 fprintf(stderr, "Need arg\n");
28 * All Lua contexts are held in this structure. We work with it almost
33 luaL_openlibs(L); /* Load Lua libraries */
35 /* Load the file containing the script we are going to run */
36 status = luaL_loadfile(L, argv[1]);
39 (void)fprintf(stderr, "bad, bad file\n");
43 /* Ask Lua to run our little script */
44 result = lua_pcall(L, 0, LUA_MULTRET, 0);
47 fprintf(stderr, "%s\n", lua_pushfstring(L, "error calling "
48 LUA_QL("print") " (%s)", lua_tostring(L, -1)));
52 lua_pop(L, 1); /* Take the returned value out of the stack */
53 lua_close(L); /* Cya, Lua */