Merge pull request #1 from dcreager/tables

Allow tables to be copied between threads
master
Robert G. Jakabosky 15 years ago
commit 32378b2af4

@ -921,6 +921,7 @@ static int llthread_move_values(lua_State *from_L, lua_State *to_L, int idx, int
size_t str_len; size_t str_len;
int nvalues = 0; int nvalues = 0;
int n; int n;
int key, value;
for(n = idx; n <= top; n++) { for(n = idx; n <= top; n++) {
/* only support string/number/boolean/nil/lightuserdata. */ /* only support string/number/boolean/nil/lightuserdata. */
@ -942,12 +943,26 @@ static int llthread_move_values(lua_State *from_L, lua_State *to_L, int idx, int
lua_pushlightuserdata(to_L, lua_touserdata(from_L, n)); lua_pushlightuserdata(to_L, lua_touserdata(from_L, n));
break; break;
case LUA_TTABLE: case LUA_TTABLE:
lua_newtable(to_L);
lua_pushnil(from_L);
while (lua_next(from_L, n) != 0) {
/* key is at -2, value at -1, but we need to normalize these
* to positive indices */
key = lua_gettop(from_L) - 1;
value = lua_gettop(from_L);
llthread_move_values(from_L, to_L, key, value, is_arg);
/* Copied key and value are now at -2 and -1 in to_L. */
lua_settable(to_L, -3);
/* Pop value for next iteration */
lua_pop(from_L, 1);
}
break;
case LUA_TFUNCTION: case LUA_TFUNCTION:
case LUA_TUSERDATA: case LUA_TUSERDATA:
case LUA_TTHREAD: case LUA_TTHREAD:
default: default:
if (is_arg) { if (is_arg) {
return luaL_argerror(from_L, n, "table/function/userdata/thread types un-supported."); return luaL_argerror(from_L, n, "function/userdata/thread types un-supported.");
} else { } else {
/* convert un-supported types to an error string. */ /* convert un-supported types to an error string. */
lua_pushfstring(to_L, "Un-supported value: %s: %p", lua_pushfstring(to_L, "Un-supported value: %s: %p",

@ -228,6 +228,7 @@ static int llthread_move_values(lua_State *from_L, lua_State *to_L, int idx, int
size_t str_len; size_t str_len;
int nvalues = 0; int nvalues = 0;
int n; int n;
int key, value;
for(n = idx; n <= top; n++) { for(n = idx; n <= top; n++) {
/* only support string/number/boolean/nil/lightuserdata. */ /* only support string/number/boolean/nil/lightuserdata. */
@ -249,12 +250,26 @@ static int llthread_move_values(lua_State *from_L, lua_State *to_L, int idx, int
lua_pushlightuserdata(to_L, lua_touserdata(from_L, n)); lua_pushlightuserdata(to_L, lua_touserdata(from_L, n));
break; break;
case LUA_TTABLE: case LUA_TTABLE:
lua_newtable(to_L);
lua_pushnil(from_L);
while (lua_next(from_L, n) != 0) {
/* key is at -2, value at -1, but we need to normalize these
* to positive indices */
key = lua_gettop(from_L) - 1;
value = lua_gettop(from_L);
llthread_move_values(from_L, to_L, key, value, is_arg);
/* Copied key and value are now at -2 and -1 in to_L. */
lua_settable(to_L, -3);
/* Pop value for next iteration */
lua_pop(from_L, 1);
}
break;
case LUA_TFUNCTION: case LUA_TFUNCTION:
case LUA_TUSERDATA: case LUA_TUSERDATA:
case LUA_TTHREAD: case LUA_TTHREAD:
default: default:
if (is_arg) { if (is_arg) {
return luaL_argerror(from_L, n, "table/function/userdata/thread types un-supported."); return luaL_argerror(from_L, n, "function/userdata/thread types un-supported.");
} else { } else {
/* convert un-supported types to an error string. */ /* convert un-supported types to an error string. */
lua_pushfstring(to_L, "Un-supported value: %s: %p", lua_pushfstring(to_L, "Un-supported value: %s: %p",

Loading…
Cancel
Save