Inheritance: IDisposable
示例#1
0
文件: LuaSvr.cs 项目: wlgys8/slua
        public void init(Action<int> tick,Action complete,LuaSvrFlag flag=LuaSvrFlag.LSF_BASIC)
        {
            LuaState luaState = new LuaState();

            IntPtr L = luaState.L;
            LuaObject.init(L);
            lgo.openDebug = (flag&LuaSvrFlag.LSF_DEBUG)!=0;

            // be caurefull here, doBind Run in another thread
            // any code access unity interface will cause deadlock.
            // if you want to debug bind code using unity interface, need call doBind directly, like:
            // doBind(L);
            ThreadPool.QueueUserWorkItem(doBind, L);

            lgo.StartCoroutine(waitForBind(tick, () =>
            {
                this.luaState = luaState;
                doinit(L,flag);
                if (lgo.openDebug)
                {
                    lgo.StartCoroutine(waitForDebugConnection(() =>
                    {
                        complete();
                        checkTop(L);
                    }));
                }
                else
                {
                    complete();
                    checkTop(L);
                }
            }));
        }
示例#2
0
        public void init(Action<int> tick,Action complete,bool debug=false)
        {
            LuaState luaState = new LuaState();

            IntPtr L = luaState.L;
            LuaObject.init(L);

            ThreadPool.QueueUserWorkItem(doBind, L);

            lgo.StartCoroutine(waitForBind(tick, () =>
            {
                this.luaState = luaState;
                doinit(L);
                if (debug)
                {
                    lgo.StartCoroutine(waitForDebugConnection(() =>
                    {
                        complete();
                        checkTop(L);
                    }));
                }
                else
                {
                    complete();
                    checkTop(L);
                }
            }));
        }
示例#3
0
		//初始化
		private void init()
		{
//			if (mLuaState != null) {
//				mLuaState.Dispose ();
//			}
			#if UNITY_EDITOR
				LuaFileUtils.Instance.beZip = UseAssetBundleLuaInEditor;
			#else
				LuaFileUtils.Instance.beZip = true;
			#endif
			mLuaState = new LuaState();
			mLuaState.LogGC = false;
			mLuaState.Start();
			LuaBinder.Bind(mLuaState);
			mLuaState.DoFile(LuaFileUtils.Instance.beZip?LuaEnterFile:LuaEnterDebugFile);

			//协程
			luaCoroutine = GameObject.Find ("LuaCoroutine");
			if (luaCoroutine == null) {
				luaCoroutine = new GameObject ();
				luaCoroutine.gameObject.name = "LuaCoroutine";
				luaCoroutine.AddComponent<LuaCoroutineComponent> ();
				UnityEngine.Object.DontDestroyOnLoad(luaCoroutine);
			}
			LuaCoroutine.Register(mLuaState, luaCoroutine.GetComponent<LuaCoroutineComponent>());

			addFunc(FuncName.createLuaFile);

		}
        public ObjectTranslator(LuaState interpreter,IntPtr luaState)
        {
            this.interpreter=interpreter;
            typeChecker=new CheckType(this);
            metaFunctions=new MetaFunctions(this);
            assemblies=new List<Assembly>();
            assemblies.Add(Assembly.GetExecutingAssembly());

            importTypeFunction = new LuaCSFunction(ObjectTranslator.importType);
            loadAssemblyFunction = new LuaCSFunction(ObjectTranslator.loadAssembly);
            registerTableFunction = new LuaCSFunction(ObjectTranslator.registerTable);
            unregisterTableFunction = new LuaCSFunction(ObjectTranslator.unregisterTable);
            getMethodSigFunction = new LuaCSFunction(ObjectTranslator.getMethodSignature);
            getConstructorSigFunction = new LuaCSFunction(ObjectTranslator.getConstructorSignature);

            ctypeFunction = new LuaCSFunction(ObjectTranslator.ctype);
            enumFromIntFunction = new LuaCSFunction(ObjectTranslator.enumFromInt);

            createLuaObjectList(luaState);
            createIndexingMetaFunction(luaState);
            createBaseClassMetatable(luaState);
            createClassMetatable(luaState);
            createFunctionMetatable(luaState);
            setGlobalFunctions(luaState);
        }
 // Use this for initialization
 void Awake() {
     loader = new LuaLoader();
     lua = new LuaState();
     this.InitLuaLibrary();
     LuaBinder.Bind(lua);
     LuaCoroutine.Register(lua, this);
 }
示例#6
0
文件: LuaEvent.cs 项目: zlanr/tolua
 void Clear()
 {
     //_call = null;
     _add = null;
     _remove = null;
     self = null;            
     luaState = null;
 }
示例#7
0
 public LuaFunction(LuaCSFunction function, LuaState interpreter)
 {
     _Reference = 0;
     this.function = function;
     _Interpreter = interpreter;
     L = _Interpreter.L;
     translator = _Interpreter.translator;            
 }
示例#8
0
 public LuaFunction(int reference, LuaState interpreter)
 {            
     _Reference = reference;
     this.function = null;
     _Interpreter = interpreter;
     L = _Interpreter.L;
     translator = _Interpreter.translator;            
 }
示例#9
0
        public void Close()
        {
            loop.Destroy();
            loop = null;

            lua.Dispose();
            lua = null;
            loader = null;
        }
示例#10
0
        // Use this for initialization
        void Awake()
        {
            loader = new LuaLoader();
            lua = new LuaState();
            this.OpenLibs();
            lua.LuaSetTop(0);

            LuaBinder.Bind(lua);
            LuaCoroutine.Register(lua, this);
        }
示例#11
0
文件: LuaEvent.cs 项目: benbon/tolua
        //LuaFunction _call = null;

        public LuaEvent(LuaTable table)            
        {
            self = table;
            luaState = table.GetLuaState();
            self.AddRef();

            _add = self.RawGetLuaFunction("Add");
            _remove = self.RawGetLuaFunction("Remove");
            //_call = self.RawGetLuaFunction("__call");            
        }
示例#12
0
		public DebugInterface(LuaState L)
		{
			state=L;
			instance=this;

			IntPtr l = L.L;
			getTypeTable(l, "LuaDebugger");
			addMember(l, output, false);
			addMember(l, onBreak, false);
			addMember(l, md5, false);
			createTypeMetatable(l, typeof(DebugInterface));
		}
示例#13
0
文件: LuaEvent.cs 项目: zlanr/tolua
        //LuaFunction _call = null;

        public LuaEvent(LuaTable table)            
        {
            self = table;
            luaState = table.GetLuaState();
            self.AddRef();

            LuaTable meta = self.GetMetaTable();
            _add = meta.RawGetLuaFunction("Add");
            _remove = meta.RawGetLuaFunction("Remove");
            meta.Dispose();
            meta = null;
            //_call = self.RawGetLuaFunction("__call");            
        }
示例#14
0
 public virtual void Dispose(bool disposeManagedResources)
 {
     if (!_Disposed)
     {
         if (disposeManagedResources)
         {
             if (_Reference != 0)
                 _Interpreter.dispose(_Reference);
         }
         _Interpreter = null;
         _Disposed = true;
     }
 }
示例#15
0
 static int OpenLibs(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaInterface.LuaState arg0 = (LuaInterface.LuaState)ToLua.CheckObject <LuaInterface.LuaState>(L, 1);
         LuaLog.OpenLibs(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
        // make sure lua state finalize at last
        // make sure LuaSvrGameObject excute order is max(9999)
        void OnDestroy()
        {
            if (state != null)
            {
                if (di != null)
                {
                    di.close();
                    di = null;
                }

                state.Dispose();
                state = null;
            }
        }
示例#17
0
 static int SetMainLuaEnv(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaInterface.LuaState arg0 = (LuaInterface.LuaState)ToLua.CheckObject <LuaInterface.LuaState>(L, 1);
         MikuLuaProfiler.LuaProfiler.SetMainLuaEnv(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static int GetLuaState(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaFramework.LuaManager obj = (LuaFramework.LuaManager)ToLua.CheckObject <LuaFramework.LuaManager>(L, 1);
         LuaInterface.LuaState   o   = obj.GetLuaState();
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
示例#19
0
        public virtual void Dispose(bool disposeManagedResources)
        {
            if (!beDisposed)
            {
                beDisposed = true;   

                if (reference > 0 && luaState != null)
                {
                    luaState.CollectRef(reference, name, !disposeManagedResources);
                }
                
                reference = 0;
                luaState = null;                             
            }            
        }
示例#20
0
    /// <summary>
    /// Initializes a new instance of the <see cref="UniWebViewMessage"/> struct.
    /// </summary>
    /// <param name="rawMessage">Raw message which will be parsed to a UniWebViewMessage.</param>
    public UniWebViewMessage(string rawMessage) : this()
    {
        this.rawMessage = rawMessage;
        string[] schemeSplit = rawMessage.Split(new string[] { "://" }, System.StringSplitOptions.None);
        if (schemeSplit.Length >= 2)
        {
            this.scheme = schemeSplit[0];
            string pathAndArgsString = "";
            int    index             = 1;
            while (index < schemeSplit.Length)
            {
                pathAndArgsString = string.Concat(pathAndArgsString, schemeSplit[index]);
                index++;
            }

            string[] split = pathAndArgsString.Split("?"[0]);

            this.path = split[0].TrimEnd('/');
            this.args = new Dictionary <string, string>();
            if (split.Length > 1)
            {
                foreach (string pair in split[1].Split("&"[0]))
                {
                    string[] elems = pair.Split("="[0]);
                    if (elems.Length > 1)
                    {
                        args[elems[0]] = WWW.UnEscapeURL(elems[1]);
                    }
                }
            }

            LuaInterface.LuaState luastate = LuaClient.GetMainState();
            table               = luastate.GetTable(2);
            table["scheme"]     = this.scheme;
            table["path"]       = this.path;
            table["rawMessage"] = this.rawMessage;
            foreach (KeyValuePair <string, string> kvp in args)
            {
                //Debug.Log(kvp.Key);
                //Debug.Log(kvp.Value);
                table[kvp.Key] = kvp.Value;
            }
        }
        else
        {
            Debug.LogError("Bad url scheme. Can not be parsed to UniWebViewMessage: " + rawMessage);
        }
    }
    static int get_luaState(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LuaLooper             obj = (LuaLooper)o;
            LuaInterface.LuaState ret = obj.luaState;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index luaState on a nil value"));
        }
    }
    static int get_mainLua(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LuaFramework.LuaManager obj = (LuaFramework.LuaManager)o;
            LuaInterface.LuaState   ret = obj.mainLua;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index mainLua on a nil value"));
        }
    }
示例#23
0
	static int get_Lua(IntPtr L)
	{
		object o = null;

		try
		{
			o = ToLua.ToObject(L, 1);
			LuaRoot obj = (LuaRoot)o;
			LuaInterface.LuaState ret = obj.Lua;
			ToLua.PushObject(L, ret);
			return 1;
		}
		catch(Exception e)
		{
			return LuaDLL.toluaL_exception(L, e, o, "attempt to index Lua on a nil value");
		}
	}
    static int set_luaState(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            LuaLooper             obj  = (LuaLooper)o;
            LuaInterface.LuaState arg0 = (LuaInterface.LuaState)ToLua.CheckObject <LuaInterface.LuaState>(L, 2);
            obj.luaState = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index luaState on a nil value"));
        }
    }
示例#25
0
    static int get_LuaState(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityGameFramework.Runtime.Lua.LuaComponent obj = (UnityGameFramework.Runtime.Lua.LuaComponent)o;
            LuaInterface.LuaState ret = obj.LuaState;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index LuaState on a nil value" : e.Message));
        }
    }
示例#26
0
文件: LuaSvr.cs 项目: huangkumao/slua
        public LuaSvr(string main)
        {
            luaState = new LuaState();

            GameObject go = new GameObject("LuaSvrProxy");
            lgo = go.AddComponent<LuaSvrGameObject>();
            GameObject.DontDestroyOnLoad(go);
            lgo.state = luaState;
            lgo.onUpdate = this.tick;

            LuaState.pcall(luaState.L, init);

            start(main);

            if (LuaDLL.lua_gettop(luaState.L) != errorReported)
            {
                Debug.LogError("Some function not remove temp value from lua stack. You should fix it.");
                errorReported = LuaDLL.lua_gettop(luaState.L);
            }
        }
示例#27
0
        public virtual void Dispose(bool disposeManagedResources)
        {
            if (!_Disposed)
            {
                if (_Reference != 0 && _Interpreter != null)
                {
                    if (disposeManagedResources)
                    {
                        _Interpreter.dispose(_Reference);
                        _Reference = 0;
                    }
                    else if (_Interpreter.L != IntPtr.Zero)
                    {
                        LuaScriptMgr.refGCList.Enqueue(new LuaRef(_Interpreter.L, _Reference));
                        _Reference = 0;
                    }
                }

                _Interpreter = null;
                _Disposed = true;
            }
        }
示例#28
0
 //internal int reference;
 public LuaFunction(int reference, LuaState interpreter)
 {
     _Reference = reference;
     this.function = null;
     _Interpreter = interpreter;
 }
示例#29
0
 //internal int _Reference;
 //private Lua _Interpreter;
 public LuaTable(int reference, LuaState interpreter)
 {
     _Reference   = reference;
     _Interpreter = interpreter;
 }
示例#30
0
		public static void Bind(LuaState state) {}
示例#31
0
 // Use this for initialization
 void Awake() {
     loader = new LuaLoader();
     lua = new LuaState();
     LuaBinder.Bind(lua);
 }
示例#32
0
        public LuaThread( LuaState parentState, LuaFunction threadFunc )
        {
			// Copy from parent
			this.tracebackFunction = parentState.tracebackFunction;			
			this.translator = parentState.translator;
			this.translator.interpreter = this;
			
			this.panicCallback = parentState.panicCallback;

			this.printFunction = parentState.printFunction;
			this.loadfileFunction = parentState.loadfileFunction;
			this.loaderFunction = parentState.loaderFunction;
			this.dofileFunction = parentState.dofileFunction;
			
            // Assign to store
            func = threadFunc;
            parent = parentState;

            // Create Thread
            L = LuaDLL.lua_newthread( parent.L );

            // Store thread in registry
            threadRef = LuaDLL.luaL_ref( parent.L, LuaIndexes.LUA_REGISTRYINDEX );
        }
示例#33
0
 public LuaThread(int reference, LuaState state)
 {
     this.luaState = state;
     this.reference = reference;
 }
示例#34
0
        public void Close() {
            SafeRelease(ref updateFunc);
            SafeRelease(ref lateUpdateFunc);
            SafeRelease(ref fixedUpdateFunc);

            if (UpdateEvent != null) {
                UpdateEvent.Dispose();
                UpdateEvent = null;
            }

            if (LateUpdateEvent != null) {
                LateUpdateEvent.Dispose();
                LateUpdateEvent = null;
            }

            if (FixedUpdateEvent != null) {
                FixedUpdateEvent.Dispose();
                FixedUpdateEvent = null;
            }
            lua.Dispose();
            lua = null;
            loader = null;
        }
示例#35
0
 public LuaFunction(LuaCSFunction function, LuaState interpreter)
 {
     _Reference = 0;
     this.function = function;
     _Interpreter = interpreter;
 }
示例#36
0
 //internal int _Reference;
 //private Lua _Interpreter;
 public LuaUserData(int reference, LuaState interpreter)
 {
     _Reference = reference;
     _Interpreter = interpreter;
 }
示例#37
0
		public void init(Action<int> tick,Action complete,LuaSvrFlag flag=LuaSvrFlag.LSF_3RDDLL)
        {
			LuaState luaState = new LuaState();

			IntPtr L = luaState.L;
			LuaObject.init(L);

#if SLUA_STANDALONE
            doBind(L);
		    this.luaState = luaState;
            doinit(L, flag);
		    complete();
            checkTop(L);
#else
			

			// be caurefull here, doBind Run in another thread
			// any code access unity interface will cause deadlock.
			// if you want to debug bind code using unity interface, need call doBind directly, like:
			// doBind(L);
			ThreadPool.QueueUserWorkItem(doBind, L);

			lgo.StartCoroutine(waitForBind(tick, () =>
			{
				this.luaState = luaState;
				doinit(L,flag);
				complete();
				checkTop(L);
			}));
#endif
        }
示例#38
0
文件: LuaSvr.cs 项目: tenvick/hugula
 public LuaSvr()
 {
     LuaState luaState = new LuaState();
     this.luaState = luaState;
 }
示例#39
0
		public ObjectTranslator(LuaState interpreter,IntPtr luaState)
		{	
			this.interpreter=interpreter;
		}
示例#40
0
 public LuaThread(int reference, LuaState state)
 {
     this.luaState  = state;
     this.reference = reference;
 }
示例#41
0
 public LuaFunction(int reference, LuaState state)
 {
     this.reference = reference;
     this.luaState = state;
 }