lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thanks Peter - that solved the problem.

John

> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-
> bounces@bazar2.conectiva.com.br] On Behalf Of Peter Cawley
> Sent: Tuesday, 25 August 2009 23:49
> To: Lua list
> Subject: Re: Basic problem with Kahlua
> 
> 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.