diff --git a/CVRLua/Lua/LuaDefs/Vector3Defs.cs b/CVRLua/Lua/LuaDefs/Vector3Defs.cs index da88ddb..a67df48 100644 --- a/CVRLua/Lua/LuaDefs/Vector3Defs.cs +++ b/CVRLua/Lua/LuaDefs/Vector3Defs.cs @@ -686,7 +686,7 @@ static int Normalized(IntPtr p_state) static int SqrMagnitude(IntPtr p_state) { var l_argReader = new LuaArgReader(p_state); - Wrappers.Vector2 l_vec = null; + Wrappers.Vector3 l_vec = null; l_argReader.ReadObject(ref l_vec); if(!l_argReader.HasErrors()) l_argReader.PushNumber(l_vec.m_vec.sqrMagnitude); diff --git a/CVRLua/Lua/LuaDefs/Vector4Defs.cs b/CVRLua/Lua/LuaDefs/Vector4Defs.cs index 75fb602..30145bf 100644 --- a/CVRLua/Lua/LuaDefs/Vector4Defs.cs +++ b/CVRLua/Lua/LuaDefs/Vector4Defs.cs @@ -501,7 +501,7 @@ static int Normalized(IntPtr p_state) static int SqrMagnitude(IntPtr p_state) { var l_argReader = new LuaArgReader(p_state); - Wrappers.Vector2 l_vec = null; + Wrappers.Vector4 l_vec = null; l_argReader.ReadObject(ref l_vec); if(!l_argReader.HasErrors()) l_argReader.PushNumber(l_vec.m_vec.sqrMagnitude); diff --git a/CVRLua/Lua/LuaVM.cs b/CVRLua/Lua/LuaVM.cs index b49516e..3133e84 100644 --- a/CVRLua/Lua/LuaVM.cs +++ b/CVRLua/Lua/LuaVM.cs @@ -29,7 +29,7 @@ public ReferencedObject(object p_obj) readonly IntPtr m_state = IntPtr.Zero; readonly Dictionary m_objectsMap = null; - internal LuaVM(string p_name = "") + internal LuaVM(string p_name) { m_name = p_name; m_state = LuaInterop.luaL_newstate(); @@ -98,9 +98,9 @@ internal void Execute(string p_script) } } - internal void Execute(ref byte[] p_data) + internal void Execute(string p_blockName, ref byte[] p_data) { - if((LuaInterop.luaL_loadbuffer(m_state, ref p_data, p_data.Length, m_name) != LuaInterop.LUA_OK) || (LuaInterop.lua_pcall(m_state, 0, 0, 0) != LuaInterop.LUA_OK)) + if((LuaInterop.luaL_loadbuffer(m_state, ref p_data, p_data.Length, p_blockName) != LuaInterop.LUA_OK) || (LuaInterop.lua_pcall(m_state, 0, 0, 0) != LuaInterop.LUA_OK)) { LuaLogger.Log(LuaInterop.lua_tostring(m_state, -1)); LuaInterop.lua_pop(m_state, 1); @@ -359,9 +359,9 @@ public void GetStateInfo(out string p_name, out int p_line) { LuaInterop.lua_Debug l_debug = new LuaInterop.lua_Debug(); LuaInterop.lua_getstack(m_state, 1, ref l_debug); - LuaInterop.lua_getinfo(m_state, "nl", ref l_debug); - p_name = m_name; + LuaInterop.lua_getinfo(m_state, "l", ref l_debug); p_line = l_debug.currentline; + p_name = m_name; } // Classes diff --git a/CVRLua/LuaHandler.cs b/CVRLua/LuaHandler.cs index fcea502..de12400 100644 --- a/CVRLua/LuaHandler.cs +++ b/CVRLua/LuaHandler.cs @@ -100,7 +100,7 @@ internal static void Init() Lua.LuaDefs.LuaScriptDefs.Init(); } - internal LuaHandler(string p_name = "") + internal LuaHandler(string p_name) { m_eventFunctions = new Dictionary(); @@ -171,9 +171,9 @@ public void Execute(string p_code) { m_vm.Execute(p_code); } - public void Execute(ref byte[] p_data) + public void Execute(string p_blockName, ref byte[] p_data) { - m_vm.Execute(ref p_data); + m_vm.Execute(p_blockName, ref p_data); } public void CallEvent(ScriptEvent p_event, params object[] p_args) diff --git a/CVRLua/LuaScript.cs b/CVRLua/LuaScript.cs index b53087a..bbbee76 100644 --- a/CVRLua/LuaScript.cs +++ b/CVRLua/LuaScript.cs @@ -18,6 +18,11 @@ public class LuaScript : MonoBehaviour CVRInteractable m_interactable = null; CVRAttachment m_attachment = null; + ~LuaScript() + { + Core.Instance?.UnregisterScript(this); // Yes, it works + } + void Awake() { if(m_luaHandler == null) @@ -53,20 +58,22 @@ void Awake() foreach(var l_script in Scripts) { byte[] l_data = l_script.bytes; - m_luaHandler.Execute(ref l_data); + m_luaHandler.Execute(string.Format("{0}-{1}", this.name, l_script.name), ref l_data); } m_luaHandler.ParseEvents(); - m_luaHandler.CallEvent(LuaHandler.ScriptEvent.Start); - - StartCoroutine(CheckEndOfFrame()); } } + void Start() + { + m_luaHandler?.CallEvent(LuaHandler.ScriptEvent.Start); + StartCoroutine(CheckEndOfFrame()); + } + void OnDestroy() { m_luaHandler?.CallEvent(LuaHandler.ScriptEvent.OnDestroy); - Core.Instance?.UnregisterScript(this); } void Update() diff --git a/CVRLua/Main.cs b/CVRLua/Main.cs index ba06af6..96227fb 100644 --- a/CVRLua/Main.cs +++ b/CVRLua/Main.cs @@ -11,7 +11,7 @@ namespace CVRLua { public class Core : MelonLoader.MelonMod { - public const int c_modRelease = 19; + public const int c_modRelease = 20; static public Core Instance { get; private set; } = null;