[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Basic problem with Kahlua
- From: Peter Cawley <lua@...>
- Date: Tue, 25 Aug 2009 14:49:11 +0100
On Tue, Aug 25, 2009 at 2:41 PM, John C. Turnbull<ozemale@ozemail.com.au> wrote:
> final LuaClosure closure =
>
> LuaCompiler.loadstring("function doIt() john.m1(42)
> end", "doIt", state
>
> .getEnvironment());
>
> final Object runTest =
> state.getEnvironment().rawget("doIt");
>
> ...
>
> No errors are returned from the Lua compiler so why can’t it find “doIt” in
> the environment?
Assuming that the Kahlua API is similar to the standard C API,
loadstring only creates a function object - it does not execute any
Lua code. Thus the variable "closure" will contain a function, which
when executed will assign `function() john.m1(42) end` to the global
"doIt". You need to (p)call closure to actually make this happen,
after which you will be able to find "doIt" in the environment.