Re: calling lua functions from C which use libraries
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: calling lua functions from C which use libraries
 
- From: Tassilo von Parseval <tassilo.von.parseval@...>
 
- Date: 2004年6月14日 11:37:11 +0200
 
Hi!
On Mon, Jun 14, 2004 at 10:01:30AM +0100 Jamie Webb wrote:
> On Monday 14 June 2004 09:38, Tassilo von Parseval wrote:
> > Hi everyone,
> >
> > I am currently working on an Inline::Lua module for Perl and I need some
> > help on triggering lua functions from C when those functions make use of
> > lua's shipped library. I did a rather thorough scan through the mailing
> > list archive, but apparently this issue hasn't yet been brought up.
> 
> You just need to use luaopen_base(L) and friends after you've called 
> lua_open(). See section 5 of the manual.
Actually, my code is already doing this. Sorry for having omitted the
code where I create the Lua interpreter. The constructor does roughly
this:
 static lua_State *INTERPRETER;
 
 ...
 lua_State *
 interpreter (CLASS, ...) 
 char *CLASS;
 CODE:
 {
 ...
 RETVAL = INTERPRETER = lua_open();
 if (luaopen_loadlib(INTERPRETER))
 croak("Error loading standard library");
 }
 OUTPUT:
 RETVAL
To put things in context, the sequence of actions in my code is this:
 - L = lua_open
 - luaopen_loadlib(L)
 - lua_dobuffer(L, code, len, "...")
 - lua_getglobal(L, funcname)
 - <push values> with lua_push*
 - lua_pcall(L, nargs, LUA_MULTRET, 0)
 - output: lua_tostring(L, -1)
In principle I do agree, though. It should be a matter as easy as adding
one of the calls to luaopen_*.
Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval