} 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")
|