//会缓存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); }
//不缓存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); } }
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); }
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); }
public void PushSpecial(LuaType iType) { LuaBase.PushSpecial(iType); }
public void ReferenceFree(int i) { LuaBase.ReferenceFree(i); }
public void ReferencePush(int i) { LuaBase.ReferencePush(i); }
public void Insert(int iStackPos) { LuaBase.Insert(iStackPos); }
public int ReferenceCreate() { return(LuaBase.ReferenceCreate()); }
public string GetTypeName(LuaType iType) { return(LuaBase.GetTypeName(iType)); }
public int ObjLen(int index = -1) { return(LuaBase.ObjLen(index)); }
public void ArgError(int iArgNum, string strMessage) { LuaBase.ArgError(iArgNum, strMessage); }
public void RawSet(int iStackPos) { LuaBase.RawSet(iStackPos); }
public void ThrowError(string strError) { LuaBase.ThrowError(strError); }
/// <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); }
public IntPtr NewUserdata(uint iSize) { return(LuaBase.NewUserdata(iSize)); }
public int Next(int iStackPos) { return(LuaBase.Next(iStackPos)); }
public void Remove(int iStackPos) { LuaBase.Remove(iStackPos); }
public bool IsType(int iStackPos, LuaType iType) { return(LuaBase.IsType(iStackPos, iType)); }
public IntPtr GetUserdata(int iStackPos = -1) { return(LuaBase.GetUserdata(iStackPos)); }
public LuaType GetLuaType(int iStackPos = -1) { return(LuaBase.GetType(iStackPos)); }
public static void ResourceAttackMode(LuaTable entity, LuaBase mode) { //Unused }
public void CreateMetaTableType(string strName, LuaType iType) { LuaBase.CreateMetaTableType(strName, iType); }
public int Equal(int iA, int iB) { return(LuaBase.Equal(iA, iB)); }
public void Call(int iArgs, int iResults) { LuaBase.Call(iArgs, iResults); }
public int RawEqual(int iA, int iB) { return(LuaBase.RawEqual(iA, iB)); }
public void PushNil() { LuaBase.PushNil(); }
public int PCall(int iArgs, int iResults, int iErrorFunc) { return(LuaBase.PCall(iArgs, iResults, iErrorFunc)); }
public void PushUserdata(IntPtr pointer) { LuaBase.PushUserdata(pointer); }
public bool GetMetaTable(int i) { return(LuaBase.GetMetaTable(i)); }