コード例 #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 bool DoBuffer(byte[] bytes, string fn, out object ret)
        {
            // ensure no utf-8 bom, LuaJIT can read BOM, but Lua cannot!
            bytes = CleanUTF8Bom(bytes);
            ret   = null;
            int errfunc = LuaObject.PushTry(statePointer);

            if (LuaNativeMethods.luaL_loadbuffer(statePointer, bytes, bytes.Length, fn) == 0)
            {
                if (LuaNativeMethods.lua_pcall(statePointer, 0, LuaNativeMethods.LUAMultRet, errfunc) != 0)
                {
                    LuaNativeMethods.lua_pop(statePointer, 2);
                    return(false);
                }

                LuaNativeMethods.lua_remove(statePointer, errfunc); // pop error function
                ret = TopObjects(errfunc - 1);
                return(true);
            }

            string err = LuaNativeMethods.lua_tostring(statePointer, -1);

            LuaNativeMethods.lua_pop(statePointer, 2);
            throw new Exception("File " + fn + ": " + err);
        }
コード例 #3
0
        public static int luaL_dostring(IntPtr luaState, string chunk)
        {
            int result = LuaNativeMethods.luaL_loadstring(luaState, chunk);

            if (result != 0)
            {
                return(result);
            }

            return(LuaNativeMethods.lua_pcall(luaState, 0, -1, 0));
        }
コード例 #4
0
ファイル: LuaState.cs プロジェクト: BraedonWooding/slua
        public static void ProtectedCall(IntPtr ptr, LuaCSFunction f)
        {
            int err = LuaObject.PushTry(ptr);

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

            LuaNativeMethods.lua_remove(ptr, err);
        }
コード例 #5
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 */
        }
コード例 #6
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);
        }