|
|
发表于 2008-5-24 19:30:00
|
显示全部楼层
Re: 初学 Lua 心得
我也跟楼主一样刚刚接触Lua,也遇到了楼主的luaopen_io就down掉的问题,原因是调用顺序的问题(实际上是环境表冲突的问题),在新版lua中,已经使用一个函数luaL_openlibs来加载基本的一些库,再lua5.1.3中这个函数的代码如下所示,揭示了库的加载顺序:
static const luaL_Reg lualibs[] = {
{"", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug},
{NULL, NULL}
};
LUALIB_API void luaL_openlibs (lua_State *L) {
const luaL_Reg *lib = lualibs;
for (; lib->func; lib++) {
lua_pushcfunction(L, lib->func);
lua_pushstring(L, lib->name);
lua_call(L, 1, 0);
}
} |
|