Example #1
0
        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);
        }
Example #2
0
        public void SetObject(int reference, string field, object o)
        {
            int oldTop = LuaNativeMethods.lua_gettop(statePointer);

            LuaNativeMethods.lua_getref(statePointer, reference);
            SetObject(field.Split(new char[] { '.' }), o);
            LuaNativeMethods.lua_settop(statePointer, oldTop);
        }
Example #3
0
 public static void RemoveDelgate(IntPtr ptr, int r)
 {
     LuaNativeMethods.lua_getglobal(ptr, DelgateTable);
     LuaNativeMethods.lua_getref(ptr, r);    // push key
     LuaNativeMethods.lua_pushnil(ptr);      // push nil value
     LuaNativeMethods.lua_settable(ptr, -3); // remove function from __LuaDelegate table
     LuaNativeMethods.lua_pop(ptr, 1);       // pop __LuaDelegate
 }
Example #4
0
        public void SetObject(int reference, object field, object o)
        {
            int oldTop = LuaNativeMethods.lua_gettop(statePointer);

            LuaNativeMethods.lua_getref(statePointer, reference);
            LuaObject.PushObject(statePointer, field);
            LuaObject.PushObject(statePointer, o);
            LuaNativeMethods.lua_settable(statePointer, -3);
            LuaNativeMethods.lua_settop(statePointer, oldTop);
        }
Example #5
0
        public object GetObject(int reference, string field)
        {
            int oldTop = LuaNativeMethods.lua_gettop(statePointer);

            LuaNativeMethods.lua_getref(statePointer, reference);
            object returnValue = GetObject(field.Split(new char[] { '.' }));

            LuaNativeMethods.lua_settop(statePointer, oldTop);
            return(returnValue);
        }
Example #6
0
        public object GetObject(int reference, object field)
        {
            int oldTop = LuaNativeMethods.lua_gettop(statePointer);

            LuaNativeMethods.lua_getref(statePointer, reference);
            LuaObject.PushObject(statePointer, field);
            LuaNativeMethods.lua_gettable(statePointer, -2);
            object returnValue = GetObject(statePointer, -1);

            LuaNativeMethods.lua_settop(statePointer, oldTop);
            return(returnValue);
        }
Example #7
0
        public int PushTry()
        {
            if (errorRef == 0)
            {
                LuaNativeMethods.lua_pushcfunction(statePointer, LuaState.errorFunc);
                LuaNativeMethods.lua_pushvalue(statePointer, -1);
                errorRef = LuaNativeMethods.luaL_ref(statePointer, LuaIndexes.LUARegistryIndex);
            }
            else
            {
                LuaNativeMethods.lua_getref(statePointer, errorRef);
            }

            return(LuaNativeMethods.lua_gettop(statePointer));
        }
Example #8
0
 public void SetObject(int reference, int index, object o)
 {
     if (index >= 1)
     {
         LuaNativeMethods.lua_getref(statePointer, reference);
         LuaObject.PushVar(statePointer, o);
         LuaNativeMethods.lua_rawseti(statePointer, -2, index);
         LuaNativeMethods.lua_pop(statePointer, 1);
     }
     else
     {
         LuaNativeMethods.lua_getref(statePointer, reference);
         LuaNativeMethods.lua_pushinteger(statePointer, index);
         LuaObject.PushVar(statePointer, o);
         LuaNativeMethods.lua_settable(statePointer, -3);
         LuaNativeMethods.lua_pop(statePointer, 1);
     }
 }
Example #9
0
 public object GetObject(int reference, int index)
 {
     if (index >= 1)
     {
         LuaNativeMethods.lua_getref(statePointer, reference);
         LuaNativeMethods.lua_rawgeti(statePointer, -1, index);
         object returnValue = GetObject(statePointer, -1);
         LuaNativeMethods.lua_pop(statePointer, 2);
         return(returnValue);
     }
     else
     {
         LuaNativeMethods.lua_getref(statePointer, reference);
         LuaNativeMethods.lua_pushinteger(statePointer, index);
         LuaNativeMethods.lua_gettable(statePointer, -2);
         object returnValue = GetObject(statePointer, -1);
         LuaNativeMethods.lua_pop(statePointer, 2);
         return(returnValue);
     }
 }
Example #10
0
 public static void PushCSFunction(IntPtr ptr, LuaCSFunction function)
 {
     LuaNativeMethods.lua_getref(ptr, Get(ptr).callCSFunctionRef);
     LuaNativeMethods.lua_pushcclosure(ptr, function, 0);
     LuaNativeMethods.lua_call(ptr, 1, 1);
 }
Example #11
0
 public void Reset()
 {
     LuaNativeMethods.lua_getref(table.VariablePointer, table.Reference);
     tableIndex = LuaNativeMethods.lua_gettop(table.VariablePointer);
 }
Example #12
0
 public void Push(IntPtr ptr)
 {
     LuaNativeMethods.lua_getref(ptr, valueref);
 }