В архиве с исходниками lua есть папка etc, там есть пример вызова ф-ии. Вот мой код, но я толком не разобрался. По идее должен выполниться скрипт test.lua и вывести на консоль Hello World
Код | #include <stdio.h>
extern "C" { #include <lua.h> #include <lualib.h> #include <lauxlib.h> }
int main(int argc, char* argv[ ]) { int iErr = 0; lua_State *lua = lua_open (); // Open Lua luaopen_base(lua); /* opens the basic library */ luaopen_table(lua); /* opens the table library */ luaopen_io(lua); /* opens the I/O library */ luaopen_string(lua); /* opens the string lib. */ luaopen_math(lua); /* opens the math lib. */
if ((iErr = luaL_loadfile (lua, "test.lua")) == 0) { // Call main... if ((iErr = lua_pcall (lua, 0, LUA_MULTRET, 0)) == 0) { // Push the function name onto the stack lua_pushstring (lua, "helloWorld"); // Function is located in the Global Table lua_gettable (lua, LUA_GLOBALSINDEX); lua_pcall (lua, 0, 0, 0); } } lua_close (lua); return 0; }
|
Собственно скрипт
Код | -- Lua Hello World (test.lua) function helloWorld () io.write ("hello World") trace ("trace working now :)") end
|
В папке doc есть мануал, в нем есть раздел по С API. Ну и http://borland.xportal.ru/forum/viewtopic.php?t=21844&highlight=lua |