[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Preserving globals between chunks
- From: "Paul Moore" <p.f.moore@...>
- Date: Wed, 9 Jul 2008 23:23:22 +0100
I'm trying to write some C code that executes user-supplied chunks. I
want to use the same environment between chunks, so that (for example)
my_execute_chunk(L, "function f() print(\"Hello, world\") end")
should print "Hello, world".
At the moment, it doesn't, because each chunk is evaluated with a
local scope, so that the f defined in the first chunk is lost, and f
in the second chunk is nil.
I've tried simple things like "function _G.f() ..." but that doesn't
seem to help here. I expect I'm doing something silly, but I don't see
what. Can anyone help?
(BTW, my_execute_chunk is pretty trivial, just a sequence of
luaL_loadbuffer, then lua_pcall)