lua-users home
lua-l archive

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


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

    static lua_State *INTERPRETER;

    lua_State *
    interpreter (CLASS, ...) 
            char *CLASS;
                RETVAL = INTERPRETER = lua_open();
                if (luaopen_loadlib(INTERPRETER))
                    croak("Error loading standard library");

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_*.