作者:糖果

下面是代码:

local lua_script = [[
     local var = 1
     print(var)
]]


local  script = lua_script 
local tb=assert(loadstring(script))()
print(tb[0].text)
const char* testfunc = "print (add(1.0, 2.0)) print(sub(20.1, 19))";

int main()
{
        lua_State* L = luaL_newstate();
        luaL_openlibs(L);
        lua_register(L, "add", add);
        lua_register(L, "sub", sub);

        if (luaL_dostring(L, testfunc))
                printf("Failed to invoke.\n");

        lua_close(L);
        return 0;
}

糖果实验室
www.lua.ren/topic/158