public static void luaL_openlibs(lua_State L) { for (int i = 0; i < lualibs.Length - 1; i++) { luaL_Reg lib = lualibs[i]; lua_pushcfunction(L, lib.func); lua_pushstring(L, lib.name); lua_call(L, 1, 0); } luaL_loadfile(L, "mime.lua"); lua_pcall(L, 0, 0, 0); luaL_loadfile(L, "socket.lua"); lua_pcall(L, 0, 0, 0); /*luaL_loadfile(L, "socket/ftp.lua"); * lua_pcall(L, 0, 0, 0); * luaL_loadfile(L, "socket/http.lua"); * lua_pcall(L, 0, 0, 0); * luaL_loadfile(L, "socket/smtp.lua"); * lua_pcall(L, 0, 0, 0); * luaL_loadfile(L, "socket/tp.lua"); * lua_pcall(L, 0, 0, 0);*/ luaL_loadfile(L, "socket/url.lua"); lua_pcall(L, 0, 0, 0); luaL_loadfile(L, "ltn12.lua"); lua_pcall(L, 0, 0, 0); }
public static void luaL_openlibs(lua_State L) { /* call open functions from 'loadedlibs' */ for (int i = 0; i < loadedlibs.Length - 1; i++) { luaL_Reg lib = loadedlibs[i]; lua_pushcfunction(L, lib.func); lua_pushstring(L, lib.name); lua_call(L, 1, 0); } /* add open functions from 'preloadedlibs' into 'package.preload' table */ //lib = preloadedlibs; luaL_findtable(L, LUA_GLOBALSINDEX, "package.preload", 0); for (int i = 0; i < preloadedlibs.Length - 1; i++) { luaL_Reg lib = preloadedlibs[i]; lua_pushcfunction(L, lib.func); lua_setfield(L, -2, lib.name); } lua_pop(L, 1); /* remove package.preload table */ #if LUA_COMPAT_DEBUGLIB lua_getglobal(L, "require"); lua_pushliteral(L, LUA_DBLIBNAME); lua_call(L, 1, 0); /* call 'require"debug"' */ #endif }
public static void luaL_openlibs(LuaState L) { for (int i = 0; i < lualibs.Length - 1; i++) { luaL_Reg lib = lualibs[i]; lua_pushcfunction(L, lib.func); lua_pushstring(L, lib.name); lua_call(L, 1, 0); } }
public static void luaL_openlibs(lua_State L) { //const luaL_Reg *lib; /* "require" functions from 'loadedlibs' and set results to global table */ for (int i = 0; i < loadedlibs.Length - 1; i++) //FIXME: changed { luaL_Reg lib = loadedlibs[i]; //FIXME: added luaL_requiref(L, lib.name, lib.func, 1); lua_pop(L, 1); /* remove lib */ } }
//#endif /* }====================================================== */ /* ** set functions from list 'l' into table at top - 'nup'; each ** function gets the 'nup' elements at the top as upvalues. ** Returns with only the table at the stack. */ public static void luaL_setfuncs(lua_State L, /*const*/ luaL_Reg[] l, int nup) { luaL_checkstack(L, nup, "too many upvalues"); for (int idxL = 0; idxL < l.Length && l[idxL].name != null; idxL++) /* fill the table with given functions */ //FIXME:changed://for (; l != null && l.name; l++) { { luaL_Reg l_ = l[idxL]; int i; for (i = 0; i < nup; i++) /* copy upvalues to the top */ { lua_pushvalue(L, -nup); } lua_pushcclosure(L, l_.func, nup); /* closure with those upvalues */ lua_setfield(L, -(nup + 2), l_.name); } lua_pop(L, nup); /* remove upvalues */ }
public static void luaL_openlibs(lua_State L) { //const luaL_Reg *lib; /* call open functions from 'loadedlibs' and set results to global table */ for (int i = 0; i < loadedlibs.Length - 1; i++) //FIXME: changed { luaL_Reg lib = loadedlibs[i]; //FIXME: added luaL_requiref(L, lib.name, lib.func, 1); lua_pop(L, 1); /* remove lib */ } /* add open functions from 'preloadedlibs' into 'package.preload' table */ luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); for (int i = 0; i < preloadedlibs.Length - 1; i++) //FIXME: changed { luaL_Reg lib = preloadedlibs[i]; //FIXME: added lua_pushcfunction(L, lib.func); lua_setfield(L, -2, lib.name); } lua_pop(L, 1); /* remove _PRELOAD table */ }
public static void luaI_openlib(LuaState L, CharPtr libname, luaL_Reg[] l, int nup) { if (libname != null) { int size = libsize(l); /* check whether lib already exists */ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); lua_getfield(L, -1, libname); /* get _LOADED[libname] */ if (!lua_istable(L, -1)) { /* not found? */ lua_pop(L, 1); /* remove previous result */ /* try global variable (and create one if it does not exist) */ if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != null) luaL_error(L, "name conflict for module " + LUA_QS, libname); lua_pushvalue(L, -1); lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ } lua_remove(L, -2); /* remove _LOADED table */ lua_insert(L, -(nup + 1)); /* move library table to below upvalues */ } int reg_num = 0; for (; l[reg_num].name != null; reg_num++) { int i; for (i = 0; i < nup; i++) /* copy upvalues to the top */ lua_pushvalue(L, -nup); lua_pushcclosure(L, l[reg_num].func, nup); lua_setfield(L, -(nup + 2), l[reg_num].name); } lua_pop(L, nup); /* remove upvalues */ }
// we could just take the .Length member here, but let's try // to keep it as close to the C implementation as possible. private static int libsize(luaL_Reg[] l) { int size = 0; for (; l[size].name != null; size++) ; return size; }
public static void luaL_register(LuaState L, CharPtr libname, luaL_Reg[] l) { luaI_openlib(L, libname, l, 0); }
public static extern void luaL_setfuncs(lua_State L, luaL_Reg[] l, int nup);
/* ** =============================================================== ** some useful macros ** =============================================================== */ public static void luaL_newlibtable(lua_State L, luaL_Reg[] l) { lua_createtable(L, 0, l.Length); }
public static void luaL_newlib(lua_State L, luaL_Reg[] l) { luaL_checkversion(L); luaL_newlibtable(L, l); luaL_setfuncs(L, l, 0); }
public static extern void luaI_openlib(lua_State L, string libname, ref luaL_Reg l, int nup);
public static extern void luaL_register(lua_State L, string libname, ref luaL_Reg l);