예제 #1
0
        internal static int OpenLib(ILuaState lua)
        {
            NameFuncPair[] define = new NameFuncPair[]
            {
                new NameFuncPair("assert", LuaBaseLib.B_Assert),
                new NameFuncPair("collectgarbage", LuaBaseLib.B_CollectGarbage),
                new NameFuncPair("dofile", LuaBaseLib.B_DoFile),
                new NameFuncPair("error", LuaBaseLib.B_Error),
                new NameFuncPair("ipairs", LuaBaseLib.B_Ipairs),
                new NameFuncPair("loadfile", LuaBaseLib.B_LoadFile),
                new NameFuncPair("load", LuaBaseLib.B_Load),
                new NameFuncPair("loadstring", LuaBaseLib.B_Load),
                new NameFuncPair("next", LuaBaseLib.B_Next),
                new NameFuncPair("pairs", LuaBaseLib.B_Pairs),
                new NameFuncPair("pcall", LuaBaseLib.B_PCall),
                new NameFuncPair("print", LuaBaseLib.B_Print),
                new NameFuncPair("rawequal", LuaBaseLib.B_RawEqual),
                new NameFuncPair("rawlen", LuaBaseLib.B_RawLen),
                new NameFuncPair("rawget", LuaBaseLib.B_RawGet),
                new NameFuncPair("rawset", LuaBaseLib.B_RawSet),
                new NameFuncPair("select", LuaBaseLib.B_Select),
                new NameFuncPair("getmetatable", LuaBaseLib.B_GetMetaTable),
                new NameFuncPair("setmetatable", LuaBaseLib.B_SetMetaTable),
                new NameFuncPair("tonumber", LuaBaseLib.B_ToNumber),
                new NameFuncPair("tostring", LuaBaseLib.B_ToString),
                new NameFuncPair("type", LuaBaseLib.B_Type),
                new NameFuncPair("xpcall", LuaBaseLib.B_XPCall),
            };

            // set global _G
            lua.PushGlobalTable();
            lua.PushGlobalTable();
            lua.SetField(-2, "_G");

            // open lib into global lib
            lua.L_SetFuncs(define, 0);
            // lua.RegisterGlobalFunc( "type",  LuaBaseLib.B_Type );
            // lua.RegisterGlobalFunc( "pairs",     LuaBaseLib.B_Pairs );
            // lua.RegisterGlobalFunc( "ipairs",    LuaBaseLib.B_Ipairs );
            // lua.RegisterGlobalFunc( "print",	LuaBaseLib.B_Print );
            // lua.RegisterGlobalFunc( "tostring",	LuaBaseLib.B_ToString );

            lua.PushString(LuaDef.LUA_VERSION);
            lua.SetField(-2, "_VERSION");

            return(1);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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
        }
예제 #5
0
 public void RegisterFunction(UniLua.NameFuncPair namefunc)
 {
     NameFuncPair[] namefuncs = new NameFuncPair[] { namefunc };
     RegisterFunctions(namefuncs);
 }