コード例 #1
0
ファイル: LuaState.cs プロジェクト: BraedonWooding/slua
        public bool ProtectedCall(int args, int errfunc)
        {
            if (!state.IsMainThread())
            {
                Logger.LogError("Can't call lua function in bg thread");
                return(false);
            }

            LuaNativeMethods.lua_getref(VariablePointer, valueref);

            if (!LuaNativeMethods.lua_isfunction(VariablePointer, -1))
            {
                LuaNativeMethods.lua_pop(VariablePointer, 1);
                throw new Exception("Call invalid function.");
            }

            LuaNativeMethods.lua_insert(VariablePointer, -args - 1);
            if (LuaNativeMethods.lua_pcall(VariablePointer, args, -1, errfunc) != 0)
            {
                LuaNativeMethods.lua_pop(VariablePointer, 1);
                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: LuaState.cs プロジェクト: BraedonWooding/slua
        public static int ProtectedCall(IntPtr ptr)
        {
            int status;

            if (LuaNativeMethods.lua_type(ptr, 1) != LuaTypes.TYPE_FUNCTION)
            {
                return(LuaObject.Error(ptr, "arg 1 expect function"));
            }

            LuaNativeMethods.luaL_checktype(ptr, 1, LuaTypes.TYPE_FUNCTION);
            status = LuaNativeMethods.lua_pcall(ptr, LuaNativeMethods.lua_gettop(ptr) - 1, LuaNativeMethods.LUAMultRet, 0);
            LuaNativeMethods.lua_pushboolean(ptr, status == 0);
            LuaNativeMethods.lua_insert(ptr, 1);
            return(LuaNativeMethods.lua_gettop(ptr));  /* return status + all results */
        }
コード例 #3
0
        public static int LuaUnaryOp(IntPtr ptr, string f, string tip)
        {
            int err = GetOpFunction(ptr, f, tip);

            LuaNativeMethods.lua_pushvalue(ptr, 1);
            if (LuaNativeMethods.lua_pcall(ptr, 1, 1, err) != 0)
            {
                LuaNativeMethods.lua_pop(ptr, 1);
            }

            LuaNativeMethods.lua_remove(ptr, err);
            PushValue(ptr, true);
            LuaNativeMethods.lua_insert(ptr, -2);
            return(2);
        }
コード例 #4
0
ファイル: LuaState.cs プロジェクト: BraedonWooding/slua
        public static int Loader(IntPtr ptr)
        {
            string fileName = LuaNativeMethods.lua_tostring(ptr, 1);

            byte[] bytes = LoadFile(fileName);
            if (bytes != null)
            {
                if (LuaNativeMethods.luaL_loadbuffer(ptr, bytes, bytes.Length, "@" + fileName) == 0)
                {
                    LuaObject.PushValue(ptr, true);
                    LuaNativeMethods.lua_insert(ptr, -2);
                    return(2);
                }
                else
                {
                    string errstr = LuaNativeMethods.lua_tostring(ptr, -1);
                    return(LuaObject.Error(ptr, errstr));
                }
            }

            LuaObject.PushValue(ptr, true);
            LuaNativeMethods.lua_pushnil(ptr);
            return(2);
        }
コード例 #5
0
 public static void lua_setglobal(IntPtr luaState, string name)
 {
     LuaNativeMethods.lua_pushstring(luaState, name);
     LuaNativeMethods.lua_insert(luaState, -2);
     LuaNativeMethods.lua_settable(luaState, LuaIndexes.LUAGlobalIndex);
 }
コード例 #6
0
 public static int Ok(IntPtr ptr, int retCount)
 {
     LuaNativeMethods.lua_pushboolean(ptr, true);
     LuaNativeMethods.lua_insert(ptr, -(retCount + 1));
     return(retCount + 1);
 }