2014年04月05日 18:57 GMT+02:00 Rena <hyperhacker@gmail.com>:
I've actually implemented some functions that can copy nearly any value between Lua states: http://pastie.org/8996668
Hi,
When you copy Lua functions, you should also take care of their upvalues else they won't work as expected (if at all) in the destination state.
You may want to have a look at lanes, which supports inter-state data copying.
--
Benoit.
--if(luaL_getmetafield(from, pos, "__xcopy")) { //-1: func
lua_pushvalue(from, pos); //-1: obj, -2: func
lua_pushlightuserdata(from, to); //-1: to, -2: obj, -3: func
- lua_call(from, 2, 0); //-1: result
+ lua_call(from, 2, 1); //-1: result
int res = lua_toboolean(from, -1);
lua_pop(from, 1); //remove result
return res;