[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Modifying lua code from c at runtime
- From: "Tom Miles" <Tom@...>
- Date: Wed, 3 Feb 2010 11:40:22 -0000
Terrible bad form replying to my own email I know, but the method I've
used did work after all. I mistook the fact that when I tested it, I
didn't notice that luaL_loadstring had returned non 0, so that's why I
couldn't call the new code. :)
Sorry for the noise,
Tom
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Tom Miles
Sent: 03 February 2010 10:23
To: lua@bazar2.conectiva.com.br
Subject: Modifying lua code from c at runtime
Hello there,
At my bosses request I am having to move some of the more time critical
code in our project from lua to C++. For the most part this is pretty
easy, but I have encountered a problem where I modify the code in one
lua state from another one. My question therefore is how can I
replicate this in code? The functionality I am trying to replicate is:
p:SetGlobal("OnKey", function(key, v, ended) if key == "ESCAPE"
and ended then ClosePanel(p:Id()) end end)
i.e. I am creating a new lua function in the state of "p".
I tried:
luaL_loadstring(panel->lua_state(), "function OnKey(key, v, ended) if
key == \"ESCAPE\" and ended then
UIComponent(Component.Root()):ClosePanel()) end end");
But this just blatted over the top of existing code in the state. Is
there actually a way of doing this or am I asking too much of lua and
need to address this problem in a completely different way?
Thanks in advance,
Tom