public static bool CheckType(IntPtr ptr, int p, out LuaDelegate f)
        {
            LuaState state = LuaState.Get(ptr);

            p = LuaNativeMethods.lua_absindex(ptr, p);
            LuaNativeMethods.luaL_checktype(ptr, p, LuaTypes.TYPE_FUNCTION);

            LuaNativeMethods.lua_getglobal(ptr, DelgateTable);
            LuaNativeMethods.lua_pushvalue(ptr, p);
            LuaNativeMethods.lua_gettable(ptr, -2); // find function in __LuaDelegate table

            if (LuaNativeMethods.lua_isnil(ptr, -1))
            {                                     // not found
                LuaNativeMethods.lua_pop(ptr, 1); // pop nil
                f = NewDelegate(ptr, p);
            }
            else
            {
                int fref = LuaNativeMethods.lua_tointeger(ptr, -1);
                LuaNativeMethods.lua_pop(ptr, 1); // pop ref value;
                f = state.DelegateMap[fref];
                if (f == null)
                {
                    f = NewDelegate(ptr, p);
                }
            }

            LuaNativeMethods.lua_pop(ptr, 1); // pop DelgateTable
            return(true);
        }
Example #2
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 #3
0
        public void SetObject(string[] remainingPath, object o)
        {
            int top = LuaNativeMethods.lua_gettop(statePointer);

            for (int i = 0; i < remainingPath.Length - 1; i++)
            {
                LuaNativeMethods.lua_pushstring(statePointer, remainingPath[i]);
                LuaNativeMethods.lua_gettable(statePointer, -2);
            }

            LuaNativeMethods.lua_pushstring(statePointer, remainingPath[remainingPath.Length - 1]);
            LuaObject.PushVar(statePointer, o);
            LuaNativeMethods.lua_settable(statePointer, -3);
            LuaNativeMethods.lua_settop(statePointer, top);
        }
Example #4
0
        public object GetObject(string[] remainingPath)
        {
            object returnValue = null;

            for (int i = 0; i < remainingPath.Length; i++)
            {
                LuaNativeMethods.lua_pushstring(statePointer, remainingPath[i]);
                LuaNativeMethods.lua_gettable(statePointer, -2);
                returnValue = this.GetObject(statePointer, -1);
                LuaNativeMethods.lua_remove(statePointer, -2);
                if (returnValue == null)
                {
                    break;
                }
            }

            return(returnValue);
        }
Example #5
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 #6
0
 public static void lua_getglobal(IntPtr luaState, string name)
 {
     LuaNativeMethods.lua_pushstring(luaState, name);
     LuaNativeMethods.lua_gettable(luaState, LuaIndexes.LUAGlobalIndex);
 }