hi,我是Lua新手,尝试了一下stable,不知如何把创建的对象在多个State间共享?
下面是我写的测试代码
local print_r = require "print_r"local stable = 『More』
不欢迎 - 回复 | (2761) | 庞统 | 2014-06-05 05:43:52
hi,我是Lua新手,尝试了一下stable,不知如何把创建的对象在多个State间共享?
下面是我写的测试代码
local print_r = require "print_r"
local stable = require "stable"
local sharedobj = require "sharedobj"
local info = stable.init {
foo = { bars = "*bar", -- struct bar array
enums = "*xx", },
bar = {
first = true,
second = 1,
third = "*xx", -- enum xx array
},
xx = { "ONE", "TWO" }
}
local a = stable.create "foo"
stable.resize(a.bars,1)
stable.resize(a.enums,2)
print("=================a============")
print_r(a)
sharedobj.set("a", a.__handle)
b = stable.create("foo", sharedobj.get("a"))
print("=================b============")
print_r(b)
下面是输出结果:
=================a============
+bars+1+first [true]
| +second [1]
| +third
+enums+1 [ONE]
+2 [ONE]
=================b============
+bars
+enums
bars和enums的内容丢失了
local info = stable.init { foo = { bars = "*bar", -- struct bar array enums = "*xx", }, bar = { first = true, second = 1, third = "*xx", -- enum xx array }, xx = { "ONE", "TWO" }} - 回复 | (2762) | 庞统 | 2014-06-05 05:47:56