设为首页 加入收藏

TOP

[Lua]在C函数中保存状态--注册表,环境表,upvalue(二)
2015-11-19 23:07:28 来源: 作者: 【 】 浏览:21
Tags:Lua 函数 保存 状态 注册表 环境 upvalue
} static luaL_Reg myfuncs[] = { {"counter", counter}, {"newCounter", newCounter}, {NULL, NULL} }; extern "C" __declspec(dllexport) int luaopen_testupvalue(lua_State* L) { luaL_register(L,"testupvalue",myfuncs); return 1; } test.lua文件内容
require "testupvalue"
local fun = function()
    func = testupvalue.newCounter();
    print(func());
    print(func());
    print(func());

    func = testupvalue.newCounter();
    print(func());
    print(func());
    print(func());

    --[[ 输出结果为:
    1
    2
    3
    1
    2
    3
    --]]
end
xpcall(fun,print)
os.execute("pause")

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇c语言中获取整数和浮点数的符号位 下一篇初学Objective-C语言需要了解的星..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: