[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Modifying lua code from c at runtime
- From: "Tom Miles" <Tom@...>
- Date: Wed, 3 Feb 2010 10:23:17 -0000
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".
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,