Call which function to initialize the package.loadlib features in 5.1?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Call which function to initialize the package.loadlib features in 5.1?

jason zhang-4
Hi,
In the Lua 5.0, I call lua_loadlibopen( L ). It works well.
But in Lua 5.1, there is not lua_loadlibopen( L ); function any more.
I tried to call luaopen_package( L ), but it crashed.
 
Could any body help me?
 
Thank you.
 
 
SRC-GUI1
Tel:86-10-88366185-866
Reply | Threaded
Open this post in threaded view
|

Re: Call which function to initialize the package.loadlib features in 5.1?

Matt Campbell-2
Hello Jason:

It's easiest to open all of the standard libraries at once by calling luaL_openlibs(L). However, if you want to open the package library individually, you can do it like this:

 lua_pushcfunction(L, luaopen_package);
 lua_pushliteral(L, "package");
 lua_call(L, 1, 0);

The statements above push luaopen_package as a C function on the Lua stack, push the library name ("package") as an argument, and tell Lua to call the function, not leaving any return values on the stack. This is the way that luaL_openlibs opens each of the standard libraries.

I hope this helps.

--
Matt Campbell
Lead Programmer
Serotek Corporation
www.freedombox.info
"The Accessibility Anywhere People"


Reply | Threaded
Open this post in threaded view
|

Re: Call which function to initialize the package.loadlib features in 5.1?

Luiz Henrique de Figueiredo
> It's easiest to open all of the standard libraries at once by calling 
> luaL_openlibs(L).  However, if you want to open the package library 
> individually, you can do it like this:

The easiest way to choose which libraries to open is to edit the list
in linit.c and call luaL_openlibs(L). linit.c is meant to be edited
and added to your project -- that's why luaL_openlibs resides in a
separate module.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Call which function to initialize the package.loadlib features in 5.1?

Vyacheslav Egorov-2
In reply to this post by jason zhang-4
jason zhang wrote:
> I tried to call luaopen_package( L ), but it crashed.

See: http://www.lua.org/manual/5.1/manual.html#5

[quote]
These functions are declared in lualib.h and should not be called
directly: you must call them like any other Lua C function, e.g., by
using lua_call.
[/quote]

-- 
e.v.e


Reply | Threaded
Open this post in threaded view
|

Re: Call which function to initialize the package.loadlib featuresin 5.1?

jason zhang-4
In reply to this post by Matt Campbell-2
Thank you, it works. :)

----- Original Message ----- 
From: "Matt Campbell" <[hidden email]>
To: "Lua list" <[hidden email]>
Sent: Tuesday, August 22, 2006 10:47 AM
Subject: Re: Call which function to initialize the package.loadlib featuresin 5.1?


> Hello Jason:
> 
> It's easiest to open all of the standard libraries at once by calling 
> luaL_openlibs(L).  However, if you want to open the package library 
> individually, you can do it like this:
> 
>  lua_pushcfunction(L, luaopen_package);
>  lua_pushliteral(L, "package");
>  lua_call(L, 1, 0);
> 
> The statements above push luaopen_package as a C function on the Lua 
> stack, push the library name ("package") as an argument, and tell Lua to 
> call the function, not leaving any return values on the stack.  This is 
> the way that luaL_openlibs opens each of the standard libraries.
> 
> I hope this helps.
> 
> -- 
> Matt Campbell
> Lead Programmer
> Serotek Corporation
> www.freedombox.info
> "The Accessibility Anywhere People"
> 
>