我使用Lua 5. 2 CPI。 我试图获得一个函数来接受字符串变量或字符串字典 。
本代码 :
static int printTest(lua_State *L)
{
size_t lslen = NULL;
const char *lsrc = lua_tolstring(L, 0, &lslen);
printf("%s
", lsrc);
}
/* ----- Registration array ----- */
static const luaL_Reg testhook[] = {
{"printTest", printTest},
{NULL, NULL} /* sentinel */
};
/* ----- Registration function ----- */
LUALIB_API int registerTestHookFunctions(lua_State *L)
{
lua_newtable(L);
lua_setglobal(L, "hook");
lua_getglobal(L, "hook");
luaL_setfuncs(L, testhook, 0);
lua_settop(L, 0);
return 0;
}
当他从鲁阿那逃出来的时候,他将做这件事:
hook.printTest( hello ) -- prints hello
a = hello
hook.printTest(a) -- prints a
I m very new to Lua and using this documentation: http://www.lua.org/manual/5.2/manual.html and am not finding/understanding how to discern a variable from a literal. (There are no lua_isliteral() or lua_isvariable() methods, for example).