From 7cb15cdac5c2d1382cc46b0fa18e86aa856d53a5 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Mon, 11 Nov 2013 20:32:36 -0800 Subject: [PATCH] feat(lua): allow environment object references to be moved between Lua states Signed-off-by: Leonardo de Moura --- src/bindings/lua/environment.cpp | 2 +- src/bindings/lua/leanlua_state.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bindings/lua/environment.cpp b/src/bindings/lua/environment.cpp index 5a43787a2..dff448a0d 100644 --- a/src/bindings/lua/environment.cpp +++ b/src/bindings/lua/environment.cpp @@ -21,7 +21,7 @@ bool is_environment(lua_State * L, int idx) { return testudata(L, idx, environment_mt); } -static environment & to_environment(lua_State * L, int idx) { +environment & to_environment(lua_State * L, int idx) { return *static_cast(luaL_checkudata(L, idx, environment_mt)); } diff --git a/src/bindings/lua/leanlua_state.cpp b/src/bindings/lua/leanlua_state.cpp index acfbdf159..2a2a9f844 100644 --- a/src/bindings/lua/leanlua_state.cpp +++ b/src/bindings/lua/leanlua_state.cpp @@ -31,7 +31,7 @@ extern "C" void * lua_realloc(void *, void * q, size_t, size_t new_size) { retur namespace lean { static void open_state(lua_State * L); static void open_thread(lua_State * L); - +environment & to_environment(lua_State * L, int idx); static void copy_values(lua_State * src, int first, int last, lua_State * tgt) { for (int i = first; i <= last; i++) { if (lua_isstring(src, i)) { @@ -42,6 +42,8 @@ static void copy_values(lua_State * src, int first, int last, lua_State * tgt) { push_expr(tgt, to_expr(src, i)); } else if (is_context(src, i)) { push_context(tgt, to_context(src, i)); + } else if (is_environment(src, i)) { + push_environment(tgt, to_environment(src, i)); } else if (is_name(src, i)) { push_name(tgt, to_name(src, i)); } else if (is_mpz(src, i)) {