Game Development Reference
In-Depth Information
lua_pop(L, 2);
}
static void g_deinitializePlugin(lua_State *L) {
}
REGISTER_PLUGIN("Test", "1.0")
These plug-ins can be written in C++, Objective-C, or C. First, we include the headers of the
libraries that we need—namely gideros.h , which has the entry point to the Gideros Engine; lua.h ,
which gives us access to the Lua functions; and luaxlib.h , which provides the Lua interface
functions.
is the entry point that initializes the plug-in for the first time and
is called when Lua does not require the plug-in any more—for example, when
REGISTER_PLUGIN is used to register the plug-in to be available for use in
package.preload function and load the function that we
luaMy_func function.
local result = Test.myFunc(10,20)
print("The sum is : ", result)
To write the code for plug-ins, read up on the Lua C API found at http://www.lua.org/manual/5.2/
manual.html#4 ) . Plug-ins are similar to Lua bytecode commands, and C code can be mixed with the
Lua C API.
The following Lua code
a = f("how", t.x, 14)
when written in the Lua C API, this looks like:
lua_getglobal(L, "f");
lua_pushstring(L, "how");
lua_getglobal(L, "t");
lua_getfield(L, -1, "x");
lua_remove(L, -2);
lua_pushinteger(L, 14);
lua_call(L, 3, 1);
lua_setglobal(L, "a");
Search WWH ::




Custom Search