public static int OpenLib(ILuaState lua) { NameFuncPair[] define = new NameFuncPair[] { new NameFuncPair("abs", Math_Abs), new NameFuncPair("acos", Math_Acos), new NameFuncPair("asin", Math_Asin), new NameFuncPair("atan2", Math_Atan2), new NameFuncPair("atan", Math_Atan), new NameFuncPair("ceil", Math_Ceil), new NameFuncPair("cosh", Math_Cosh), new NameFuncPair("cos", Math_Cos), new NameFuncPair("deg", Math_Deg), new NameFuncPair("exp", Math_Exp), new NameFuncPair("floor", Math_Floor), new NameFuncPair("fmod", Math_Fmod), new NameFuncPair("frexp", Math_Frexp), new NameFuncPair("ldexp", Math_Ldexp), new NameFuncPair("log10", Math_Log10), new NameFuncPair("log", Math_Log), new NameFuncPair("max", Math_Max), new NameFuncPair("min", Math_Min), new NameFuncPair("modf", Math_Modf), new NameFuncPair("pow", Math_Pow), new NameFuncPair("rad", Math_Rad), new NameFuncPair("random", Math_Random), new NameFuncPair("randomseed", Math_RandomSeed), new NameFuncPair("sinh", Math_Sinh), new NameFuncPair("sin", Math_Sin), new NameFuncPair("sqrt", Math_Sqrt), new NameFuncPair("tanh", Math_Tanh), new NameFuncPair("tan", Math_Tan), }; lua.L_NewLib(define); lua.PushNumber(Math.PI); lua.SetField(-2, "pi"); lua.PushNumber(Double.MaxValue); lua.SetField(-2, "huge"); RandObj = new Random(); return(1); }
public static int OpenLib(ILuaState lua) { NameFuncPair[] define = new NameFuncPair[] { new NameFuncPair("concat", TBL_Concat), new NameFuncPair("maxn", TBL_MaxN), new NameFuncPair("insert", TBL_Insert), new NameFuncPair("pack", TBL_Pack), new NameFuncPair("unpack", TBL_Unpack), new NameFuncPair("remove", TBL_Remove), new NameFuncPair("sort", TBL_Sort), }; lua.L_NewLib(define); #if LUA_COMPAT_UNPACK // _G.unpack = table.unpack lua.GetField(-1, "unpack"); lua.SetGlobal("unpack"); #endif return(1); }
public static int OpenLib(ILuaState lua) { // NameFuncPair[] define = new NameFuncPair[] // { // new NameFuncPair( "module", PKG_Module ), // }; // lua.L_NewLib( define ); // // create table CLIBS to keep track of loaded C libraries // lua.L_GetSubTable( LuaDef.LUA_REGISTRYINDEX, CLIBS ); // lua.CreateTable( 0, 1 ); // metatable for CLIBS // lua.PushCSharpFunction // create `package' table NameFuncPair[] pkg_define = new NameFuncPair[] { new NameFuncPair("loadlib", PKG_LoadLib), new NameFuncPair("searchpath", PKG_SearchPath), new NameFuncPair("seeall", PKG_SeeAll), }; lua.L_NewLib(pkg_define); CreateSearchersTable(lua); #if LUA_COMPAT_LOADERS lua.PushValue(-1); // make a copy of `searchers' table lua.SetField(-3, "loaders"); // put it in field `loaders' #endif lua.SetField(-2, "searchers"); // put it in field `searchers' // set field `path' SetPath(lua, "path", LUA_PATHVERSION, LUA_PATH, LUA_PATH_DEFAULT); // set field `cpath' SetPath(lua, "cpath", LUA_CPATHVERSION, LUA_CPATH, LUA_CPATH_DEFAULT); // store config information lua.PushString(string.Format("{0}\n{1}\n{2}\n{3}\n{4}\n", LuaConf.LUA_DIRSEP, LUA_PATH_SEP, LUA_PATH_MARK, LUA_EXEC_DIR, LUA_IGMARK)); lua.SetField(-2, "config"); // set field `loaded' lua.L_GetSubTable(LuaDef.LUA_REGISTRYINDEX, "_LOADED"); lua.SetField(-2, "loaded"); // set field `preload' lua.L_GetSubTable(LuaDef.LUA_REGISTRYINDEX, "_PRELOAD"); lua.SetField(-2, "preload"); lua.PushGlobalTable(); lua.PushValue(-2); // set `package' as upvalue for next lib NameFuncPair[] loadLibFuncs = new NameFuncPair[] { new NameFuncPair("module", LL_Module), new NameFuncPair("require", LL_Require), }; lua.L_SetFuncs(loadLibFuncs, 1); // open lib into global table lua.Pop(1); // pop global table return(1); // return `package' table }