Tutorial by Examples

#include <lua.h> #include <lauxlib.h> #include <lualib.h> int main(void) { 5.1 /* Start by creating a new VM state */ lua_State *L = luaL_newstate(); /* Load standard Lua libraries: */ luaL_openlibs(L); 5.1 /* For older version of Lua use lua_open ins...
#include <stdlib.h> #include <lauxlib.h> #include <lua.h> #include <lualib.h> int main(void) { lua_State *lvm_hnd = lua_open(); luaL_openlibs(lvm_hnd); /* Load a standard Lua function from global table: */ lua_getglobal(lvm_hnd, "print&quot...
Demonstrate how to embed a lua interpreter in C code, expose a C-defined function to Lua script, evaluate a Lua script, call a C-defined function from Lua, and call a Lua-defined function from C (the host). In this example, we want the mood to be set by a Lua script. Here is mood.lua: -- Get versi...
In order to access or alter an index on a table, you need to somehow place the table into the stack. Let's assume, for this examples that your table is a global variable named tbl. Getting the content at a particular index: int getkey_index(lua_State *L) { lua_getglobal(L, "tbl"); ...

Page 1 of 1