Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Jun 5, 2023
1 parent 595c6f8 commit 12d8c0d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CVRLua/Lua/LuaDefs/Vector3Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion CVRLua/Lua/LuaDefs/Vector4Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions CVRLua/Lua/LuaVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ReferencedObject(object p_obj)
readonly IntPtr m_state = IntPtr.Zero;
readonly Dictionary<long, ReferencedObject> m_objectsMap = null;

internal LuaVM(string p_name = "")
internal LuaVM(string p_name)
{
m_name = p_name;
m_state = LuaInterop.luaL_newstate();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions CVRLua/LuaHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScriptEvent, int>();

Expand Down Expand Up @@ -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)
Expand Down
17 changes: 12 additions & 5 deletions CVRLua/LuaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion CVRLua/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 12d8c0d

Please sign in to comment.