Beispiel #1
0
    //会缓存LuaFunction
    public LuaFunction GetLuaFunction(string name)
    {
        LuaBase func = null;

        if (!_dict.TryGetValue(name, out func))
        {
            IntPtr L      = _lua.L;
            int    oldTop = LuaDLL.lua_gettop(L);

            if (PushLuaFunction(L, name))
            {
                int reference = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
                func      = new LuaFunction(reference, _lua);
                func.name = name;
                _dict.Add(name, func);
            }
            else
            {
                UnityEngine.Debug.LogWarning("Lua function " + name + " not exists");
            }

            LuaDLL.lua_settop(L, oldTop);
        }
        else
        {
            func.AddRef();
        }

        return(func as LuaFunction);
    }
Beispiel #2
0
    //不缓存LuaFunction
    public object[] CallLuaFunction(string name, params object[] args)
    {
        LuaBase lb = null;

        if (_dict.TryGetValue(name, out lb))
        {
            LuaFunction func = lb as LuaFunction;
            return(func.Call(args));
        }
        else
        {
            IntPtr      L      = _lua.L;
            LuaFunction func   = null;
            int         oldTop = LuaDLL.lua_gettop(L);

            if (PushLuaFunction(L, name))
            {
                int reference = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
                func = new LuaFunction(reference, _lua);
                LuaDLL.lua_settop(L, oldTop);
                object[] objs = func.Call(args);
                func.Dispose();
                return(objs);
            }

            return(null);
        }
    }
Beispiel #3
0
    public LuaTable GetLuaTable(string tableName)
    {
        LuaBase lt = null;

        if (!_dict.TryGetValue(tableName, out lt))
        {
            IntPtr L      = _lua.L;
            int    oldTop = LuaDLL.lua_gettop(L);

            if (PushLuaTable(L, tableName))
            {
                int reference = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
                lt      = new LuaTable(reference, _lua);
                lt.name = tableName;
                _dict.Add(tableName, lt);
            }

            LuaDLL.lua_settop(L, oldTop);
        }
        else
        {
            lt.AddRef();
        }

        return(lt as LuaTable);
    }
Beispiel #4
0
        public static int GetReference(LuaBase luaObject)
        {
            Object reference = luaObject.GetType().InvokeMember(
                "_Reference",
                BindingFlags.Public |
                BindingFlags.NonPublic |
                BindingFlags.Instance |
                BindingFlags.GetField,
                null,
                luaObject,
                null
                );

            return((int)reference);
        }
Beispiel #5
0
 public void PushSpecial(LuaType iType)
 {
     LuaBase.PushSpecial(iType);
 }
Beispiel #6
0
 public void ReferenceFree(int i)
 {
     LuaBase.ReferenceFree(i);
 }
Beispiel #7
0
 public void ReferencePush(int i)
 {
     LuaBase.ReferencePush(i);
 }
Beispiel #8
0
 public void Insert(int iStackPos)
 {
     LuaBase.Insert(iStackPos);
 }
Beispiel #9
0
 public int ReferenceCreate()
 {
     return(LuaBase.ReferenceCreate());
 }
Beispiel #10
0
 public string GetTypeName(LuaType iType)
 {
     return(LuaBase.GetTypeName(iType));
 }
Beispiel #11
0
 public int ObjLen(int index = -1)
 {
     return(LuaBase.ObjLen(index));
 }
Beispiel #12
0
 public void ArgError(int iArgNum, string strMessage)
 {
     LuaBase.ArgError(iArgNum, strMessage);
 }
Beispiel #13
0
 public void RawSet(int iStackPos)
 {
     LuaBase.RawSet(iStackPos);
 }
Beispiel #14
0
 public void ThrowError(string strError)
 {
     LuaBase.ThrowError(strError);
 }
Beispiel #15
0
 /// <summary>
 /// Checks if iStackPos is equal to the provided LuaType enumeration.
 /// </summary>
 /// <description>
 /// In addition to checking is iStackPos is equal to the LuaType,
 /// CheckType will throw a lua argument error if iStackPos is undefined.
 /// </description>
 /// <param name="iStackPos">The Lua argument to test.</param>
 /// <param name="iType">The LuaType enumeration to test against.</param>
 /// <returns>bool</returns>
 public void CheckType(int iStackPos, int iType)
 {
     LuaBase.CheckType(iStackPos, iType);
 }
Beispiel #16
0
 public IntPtr NewUserdata(uint iSize)
 {
     return(LuaBase.NewUserdata(iSize));
 }
Beispiel #17
0
 public int Next(int iStackPos)
 {
     return(LuaBase.Next(iStackPos));
 }
Beispiel #18
0
 public void Remove(int iStackPos)
 {
     LuaBase.Remove(iStackPos);
 }
Beispiel #19
0
 public bool IsType(int iStackPos, LuaType iType)
 {
     return(LuaBase.IsType(iStackPos, iType));
 }
Beispiel #20
0
 public IntPtr GetUserdata(int iStackPos = -1)
 {
     return(LuaBase.GetUserdata(iStackPos));
 }
Beispiel #21
0
 public LuaType GetLuaType(int iStackPos = -1)
 {
     return(LuaBase.GetType(iStackPos));
 }
Beispiel #22
0
 public static void ResourceAttackMode(LuaTable entity, LuaBase mode)
 {
     //Unused
 }
Beispiel #23
0
 public void CreateMetaTableType(string strName, LuaType iType)
 {
     LuaBase.CreateMetaTableType(strName, iType);
 }
Beispiel #24
0
 public int Equal(int iA, int iB)
 {
     return(LuaBase.Equal(iA, iB));
 }
Beispiel #25
0
 public void Call(int iArgs, int iResults)
 {
     LuaBase.Call(iArgs, iResults);
 }
Beispiel #26
0
 public int RawEqual(int iA, int iB)
 {
     return(LuaBase.RawEqual(iA, iB));
 }
Beispiel #27
0
 public void PushNil()
 {
     LuaBase.PushNil();
 }
Beispiel #28
0
 public int PCall(int iArgs, int iResults, int iErrorFunc)
 {
     return(LuaBase.PCall(iArgs, iResults, iErrorFunc));
 }
Beispiel #29
0
 public void PushUserdata(IntPtr pointer)
 {
     LuaBase.PushUserdata(pointer);
 }
Beispiel #30
0
 public bool GetMetaTable(int i)
 {
     return(LuaBase.GetMetaTable(i));
 }