糖果实验室杂货铺

Candy Lab

Lua动态加载脚本( loadstring )

3 years ago 0

作者:糖果

下面是代码:

None
1
2
3
4
5
6
7
8
9
local lua_script = [[
     local var = 1
     print(var)
]]


local  script = lua_script 
local tb=assert(loadstring(script))()
print(tb[0].text)
None
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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


糖果实验室

Openresty中文编程网
IKBC经典机械键盘
机械键盘领券优惠购买

Write a Comment