public LuaSvr(string main) { luaState = new LuaState(); LuaObject.init(luaState.L); bind("BindUnity"); bind("BindUnityUI"); bind("BindCustom"); bind("BindExtend"); // if you want to extend slua, can implemented BindExtend function like BindCustom etc. GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); lgo.state = luaState; lgo.onUpdate = this.tick; LuaTimer.reg(luaState.L); LuaCoroutine.reg(luaState.L, lgo); Helper.reg(luaState.L); 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); } }
public Lua() { LuaState.loaderDelegate += luaLoader; luaState = new LuaState(); // LuaDLL.lua_pushstdcallcfunction(luaState.L, import); //LuaDLL.lua_setglobal(luaState.L, "using"); LuaObject.init(luaState.L); bindAll(luaState.L); GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent<LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); lgo.state = luaState; lgo.onUpdate = this.tick; LuaTimer.reg(luaState.L); LuaCoroutine.reg(luaState.L, lgo); Helper.reg(luaState.L); LuaValueType.reg(luaState.L); LuaDLL.luaS_openextlibs(luaState.L); /* 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); } * */ }
public LuaSvr(string main) { luaState = new LuaState(); LuaObject.init(luaState.handle); bind("BindUnity"); bind("BindUnityUI"); bind("BindCustom"); if (LuaDLL.lua_gettop(luaState.handle) != 0) { Debug.LogError("Some function not remove temp value from lua stack."); } GameObject go = new GameObject("LuaSvrProxy"); LuaSvrGameObject lgo = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); lgo.state = luaState; luaState.doFile(main); LuaFunction func = (LuaFunction)luaState["main"]; func.call(); }
public LuaSvr() { GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); }
public LuaSvr(string main) { luaState = new LuaState(); LuaObject.init(luaState.L); bindAll(luaState.L); GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); lgo.state = luaState; lgo.onUpdate = this.tick; LuaTimer.reg(luaState.L); LuaCoroutine.reg(luaState.L, lgo); Helper.reg(luaState.L); try { LuaDLL.luaS_openextlibs(luaState.L); } catch (Exception) { // do nothing } 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); } }
public void init( ) { #if !SLUA_STANDALONE if (lgo == null #if UNITY_EDITOR && UnityEditor.EditorApplication.isPlaying #endif ) { GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); } #endif IntPtr L = luaState.L; LuaObject.init(L); #if SLUA_STANDALONE doBind(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); #endif }
public LuaSvr() { #if !SLUA_STANDALONE GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); #endif }
public LuaSvr() { #if !SLUA_STANDALONE GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent<LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); #endif }
public override void OnInspectorGUI() { LuaSvrGameObject myTarget = (LuaSvrGameObject)target; int bytes = LuaDLL.lua_gc(myTarget.state.L, LuaGCOptions.LUA_GCCOUNT, 0); EditorGUILayout.LabelField("Memory(Kb)", bytes.ToString()); if (GUILayout.Button("Lua GC")) { LuaDLL.lua_gc(myTarget.state.L, LuaGCOptions.LUA_GCCOLLECT, 0); } }
public override void OnInspectorGUI() { LuaSvrGameObject myTarget = (LuaSvrGameObject)target; int bytes = LuaNativeMethods.lua_gc(myTarget.State.StatePointer, LuaGCOptions.LUA_GCCOUNT, 0); EditorGUILayout.LabelField("Memory(Kb)", bytes.ToString()); if (GUILayout.Button("Lua GC")) { LuaNativeMethods.lua_gc(myTarget.State.StatePointer, LuaGCOptions.LUA_GCCOLLECT, 0); System.GC.Collect(); } }
public void init(Action <int> tick, Action complete, LuaSvrFlag flag = LuaSvrFlag.LSF_BASIC) { #if !SLUA_STANDALONE if (lgo == null #if UNITY_EDITOR && UnityEditor.EditorApplication.isPlaying #endif ) { GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); } #endif IntPtr L = luaState.L; LuaObject.init(L); #if SLUA_STANDALONE doBind(L); 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); #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlaying) { doBind(L); doinit(L, flag); complete(); checkTop(L); } else { #endif ThreadPool.QueueUserWorkItem(doBind, L); lgo.StartCoroutine(waitForBind(tick, () => { doinit(L, flag); complete(); checkTop(L); })); #if UNITY_EDITOR } #endif #endif }
public LuaSvr(bool editor = false) { this.editor = editor; if (editor) { return; } #if !SLUA_STANDALONE GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); #endif }
public void CreateGameObject() { if (gameObject == null #if UNITY_EDITOR && UnityEditor.EditorApplication.isPlaying #endif ) { GameObject go = new GameObject("LuaSvrProxy"); gameObject = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); gameObject.OnUpdate = this.Tick; gameObject.State = this; } }
void doCommand(string str) { LuaSvrGameObject lua = FindObjectOfType <LuaSvrGameObject>(); if (lua == null) { return; } LuaState luaState = lua.state; int index = str.IndexOf(" "); string cmd = str; if (index > 0) { cmd = str.Substring(0, index).Trim().ToLower(); } if (cmd == "reload") { // TODO } else if (cmd == "cls") { outputText = ""; } else { if (!string.IsNullOrEmpty(str)) { #if !CONSOLE_DEBUG var luaFunc = luaState.getFunction("Slua.ldb.printExpr"); if (luaFunc != null) { luaFunc.call(str); } else { consolePrint("do script failed"); } #else luaState.doString(str); #endif } } }
void createGameObject() { #if !SLUA_STANDALONE if (lgo == null #if UNITY_EDITOR && UnityEditor.EditorApplication.isPlaying #endif ) { GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); lgo.onUpdate = this.tick; lgo.state = this; } #endif }
public void init(Action <int> tick, Action complete, LuaSvrFlag flag = LuaSvrFlag.LSF_BASIC) { #if !SLUA_STANDALONE if (lgo == null #if UNITY_EDITOR && UnityEditor.EditorApplication.isPlaying #endif ) { GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); } #endif IntPtr L = luaState.L; LuaObject.init(L); #if SLUA_STANDALONE doBind(L); doinit(L, flag); complete(); checkTop(L); #else #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlaying) { doBind(L); doinit(L, flag); complete(); checkTop(L); } else { #endif lgo.StartCoroutine(doBind(L, tick, () => { doinit(L, flag); complete(); checkTop(L); })); #if UNITY_EDITOR } #endif #endif }
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); } }
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); } }
public void init(Action <int> tick, Action complete, LuaSvrFlag flag = LuaSvrFlag.LSF_BASIC) { #if !SLUA_STANDALONE if (lgo == null && (!SLuaSetting.IsEditor || SLuaSetting.IsPlaying)) { GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent <LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); } #endif IntPtr L = luaState.L; LuaObject.init(L); #if SLUA_STANDALONE doBind(L); 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); if (SLuaSetting.IsEditor && !SLuaSetting.IsPlaying) { doBind(L); doinit(L, flag); complete(); checkTop(L); } else { lgo.StartCoroutine(doBind(L, tick, () => { doinit(L, flag); complete(); checkTop(L); })); } #endif }
void OnGUI() { try { float totalAreaHeight = Screen.height; float outputAreaHeight = totalAreaHeight - 50; LuaSvrGameObject lua = FindObjectOfType <LuaSvrGameObject>(); if (!regConsoleFunction) { regConsoleFunction = true; RegConsoleFunction(lua.state.L); } scrollPoition = GUILayout.BeginScrollView(scrollPoition, GUILayout.ExpandWidth(true), GUILayout.Height(outputAreaHeight)); if (outputText.Length > MaxLength) { outputText = outputText.Substring(outputText.Length - MaxLength); } if (lua != null) { EditorGUILayout.TextArea(outputText, GUILayout.ExpandHeight(true)); } else { EditorGUILayout.LabelField("Start game to active this console.", GUILayout.ExpandHeight(true)); } GUILayout.EndScrollView(); GUI.SetNextControlName("Input"); if (lua != null) { inputText = EditorGUILayout.TextField(inputText, GUILayout.ExpandHeight(true)); } else { EditorGUILayout.LabelField("Waiting for lua VM start", GUILayout.ExpandHeight(true)); } if (Event.current.isKey && Event.current.type == EventType.KeyUp) { bool refresh = false; if (Event.current.keyCode == KeyCode.Return) { if (inputText != "") { if (history.Count == 0 || history[history.Count - 1] != inputText) { history.Add(inputText); } consolePrint(inputText); doCommand(inputText); inputText = ""; refresh = true; historyIndex = history.Count; } } else if (Event.current.keyCode == KeyCode.UpArrow) { if (history.Count > 0) { historyIndex = historyIndex - 1; if (historyIndex < 0) { historyIndex = 0; } else { inputText = history[historyIndex]; refresh = true; } } } else if (Event.current.keyCode == KeyCode.DownArrow) { if (history.Count > 0) { historyIndex = historyIndex + 1; if (historyIndex > history.Count - 1) { historyIndex = history.Count - 1; } else { inputText = history[historyIndex]; refresh = true; } } } if (refresh) { Repaint(); EditorGUIUtility.editingTextField = false; GUI.FocusControl("Input"); } } } catch (Exception) { // ignore } }
public void init(Action<int> tick,Action complete,LuaSvrFlag flag=LuaSvrFlag.LSF_BASIC) { #if !SLUA_STANDALONE if (lgo == null #if UNITY_EDITOR && UnityEditor.EditorApplication.isPlaying #endif ) { GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent<LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); } #endif IntPtr L = luaState.L; LuaObject.init(L); #if SLUA_STANDALONE doBind(L); 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); #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlaying) { doBind(L); doinit(L, flag); complete(); checkTop(L); } else { #endif ThreadPool.QueueUserWorkItem(doBind, L); lgo.StartCoroutine(waitForBind(tick, () => { doinit(L, flag); complete(); checkTop(L); })); #if UNITY_EDITOR } #endif #endif }
public LuaSvr() { GameObject go = new GameObject("LuaSvrProxy"); lgo = go.AddComponent<LuaSvrGameObject>(); GameObject.DontDestroyOnLoad(go); }