July 2018
Beginner
202 pages
5h 42m
English
To read a Lua variable in C, you will need to load the Lua file with int luaL_loadfile(lua_State*, const char*). The resulting chunk will then need to be executed with lua_pcall(lua_State*, int, int, int, int). After the Lua chunk is loaded and executed, any variables it declared can be read. The lua_pcall function will be described in more detail in the Calling Lua functions from C section of this chapter.
The luaL_loadfile function returns 0 on success, or one of the following enumerations on failure: LUA_ERRSYNTAX, LUA_ERRMEM, LUA_ERRFILE. The first argument to the function is the Lua state to work with, the second is the file path to load. The resulting Lua chunk is added to the Lua stack.
The lua_pcall function is ...