diff --git a/CVRLua/CVRLua.csproj b/CVRLua/CVRLua.csproj
index fe6ca29..1446617 100644
--- a/CVRLua/CVRLua.csproj
+++ b/CVRLua/CVRLua.csproj
@@ -97,6 +97,8 @@
+
+
@@ -134,6 +136,7 @@
+
diff --git a/CVRLua/Lua/LuaDefs/CollisionDefs.cs b/CVRLua/Lua/LuaDefs/CollisionDefs.cs
index 58e0c3e..4cbe254 100644
--- a/CVRLua/Lua/LuaDefs/CollisionDefs.cs
+++ b/CVRLua/Lua/LuaDefs/CollisionDefs.cs
@@ -7,7 +7,6 @@ namespace CVRLua.Lua.LuaDefs
static class CollisionDefs
{
static readonly List<(string, LuaInterop.lua_CFunction)> ms_metaMethods = new List<(string, LuaInterop.lua_CFunction)>();
- static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_staticProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
static readonly List<(string, LuaInterop.lua_CFunction)> ms_staticMethods = new List<(string, LuaInterop.lua_CFunction)>();
static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_instanceProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
static readonly List<(string, LuaInterop.lua_CFunction)> ms_instanceMethods = new List<(string, LuaInterop.lua_CFunction)>();
@@ -29,7 +28,7 @@ internal static void Init()
internal static void RegisterInVM(LuaVM p_vm)
{
- p_vm.RegisterClass(typeof(Collision), null, ms_staticProperties, ms_staticMethods, ms_metaMethods, ms_instanceProperties, ms_instanceMethods);
+ p_vm.RegisterClass(typeof(Collision), null, null, ms_staticMethods, ms_metaMethods, ms_instanceProperties, ms_instanceMethods);
}
// Static methods
diff --git a/CVRLua/Lua/LuaDefs/ContactPointDefs.cs b/CVRLua/Lua/LuaDefs/ContactPointDefs.cs
index 101bb4d..59f6a37 100644
--- a/CVRLua/Lua/LuaDefs/ContactPointDefs.cs
+++ b/CVRLua/Lua/LuaDefs/ContactPointDefs.cs
@@ -6,7 +6,6 @@ namespace CVRLua.Lua.LuaDefs
static class ContactPointDefs
{
static readonly List<(string, LuaInterop.lua_CFunction)> ms_metaMethods = new List<(string, LuaInterop.lua_CFunction)>();
- static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_staticProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
static readonly List<(string, LuaInterop.lua_CFunction)> ms_staticMethods = new List<(string, LuaInterop.lua_CFunction)>();
static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_instanceProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
static readonly List<(string, LuaInterop.lua_CFunction)> ms_instanceMethods = new List<(string, LuaInterop.lua_CFunction)>();
@@ -15,6 +14,7 @@ internal static void Init()
{
ms_staticMethods.Add((nameof(IsContactPoint), IsContactPoint));
+ ms_metaMethods.Add(("__eq", Equal));
ms_metaMethods.Add(("__tostring", ToString));
ms_instanceProperties.Add(("normal", (GetNormal, null)));
@@ -26,7 +26,7 @@ internal static void Init()
internal static void RegisterInVM(LuaVM p_vm)
{
- p_vm.RegisterClass(typeof(Wrappers.ContactPoint), null, ms_staticProperties, ms_staticMethods, ms_metaMethods, ms_instanceProperties, ms_instanceMethods);
+ p_vm.RegisterClass(typeof(Wrappers.ContactPoint), null, null, ms_staticMethods, ms_metaMethods, ms_instanceProperties, ms_instanceMethods);
}
// Static methods
@@ -40,6 +40,21 @@ static int IsContactPoint(IntPtr p_state)
}
// Metamethods
+ static int Equal(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.ContactPoint l_pointA = null;
+ Wrappers.ContactPoint l_pointB = null;
+ l_argReader.ReadObject(ref l_pointA);
+ l_argReader.ReadObject(ref l_pointB);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushBoolean(l_pointA == l_pointB);
+ else
+ l_argReader.PushBoolean(false);
+
+ return l_argReader.GetReturnValue();
+ }
+
static int ToString(IntPtr p_state)
{
var l_argReader = new LuaArgReader(p_state);
diff --git a/CVRLua/Lua/LuaDefs/DateTimeDefs.cs b/CVRLua/Lua/LuaDefs/DateTimeDefs.cs
index 3da95fe..cd4674c 100644
--- a/CVRLua/Lua/LuaDefs/DateTimeDefs.cs
+++ b/CVRLua/Lua/LuaDefs/DateTimeDefs.cs
@@ -5,11 +5,7 @@ namespace CVRLua.Lua.LuaDefs
{
static class DateTimeDefs
{
- static readonly List<(string, LuaInterop.lua_CFunction)> ms_metaMethods = new List<(string, LuaInterop.lua_CFunction)>();
- static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_staticProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
static readonly List<(string, LuaInterop.lua_CFunction)> ms_staticMethods = new List<(string, LuaInterop.lua_CFunction)>();
- static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_instanceProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
- static readonly List<(string, LuaInterop.lua_CFunction)> ms_instanceMethods = new List<(string, LuaInterop.lua_CFunction)>();
internal static void Init()
{
@@ -19,7 +15,7 @@ internal static void Init()
internal static void RegisterInVM(LuaVM p_vm)
{
- p_vm.RegisterClass(typeof(DateTime), null, ms_staticProperties, ms_staticMethods, ms_metaMethods, ms_instanceProperties, ms_instanceMethods);
+ p_vm.RegisterClass(typeof(DateTime), null, null, ms_staticMethods, null, null, null);
}
// Static methods
diff --git a/CVRLua/Lua/LuaDefs/LocalPlayerDefs.cs b/CVRLua/Lua/LuaDefs/LocalPlayerDefs.cs
index 2639ccd..04a117d 100644
--- a/CVRLua/Lua/LuaDefs/LocalPlayerDefs.cs
+++ b/CVRLua/Lua/LuaDefs/LocalPlayerDefs.cs
@@ -6,7 +6,6 @@ namespace CVRLua.Lua.LuaDefs
static class LocalPlayerDefs
{
static readonly List<(string, LuaInterop.lua_CFunction)> ms_metaMethods = new List<(string, LuaInterop.lua_CFunction)>();
- static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_staticProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
static readonly List<(string, LuaInterop.lua_CFunction)> ms_staticMethods = new List<(string, LuaInterop.lua_CFunction)>();
static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_instanceProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
static readonly List<(string, LuaInterop.lua_CFunction)> ms_instanceMethods = new List<(string, LuaInterop.lua_CFunction)>();
@@ -57,7 +56,7 @@ internal static void Init()
public static void RegisterInVM(LuaVM p_vm)
{
- p_vm.RegisterClass(typeof(Wrappers.LocalPlayer), Constructor, ms_staticProperties, ms_staticMethods, ms_metaMethods, ms_instanceProperties, ms_instanceMethods);
+ p_vm.RegisterClass(typeof(Wrappers.LocalPlayer), Constructor, null, ms_staticMethods, ms_metaMethods, ms_instanceProperties, ms_instanceMethods);
}
// Constructor
diff --git a/CVRLua/Lua/LuaDefs/MathfDefs.cs b/CVRLua/Lua/LuaDefs/MathfDefs.cs
index 67b57e1..a3ed860 100644
--- a/CVRLua/Lua/LuaDefs/MathfDefs.cs
+++ b/CVRLua/Lua/LuaDefs/MathfDefs.cs
@@ -6,11 +6,8 @@ namespace CVRLua.Lua.LuaDefs
{
static class MathfDefs
{
- static readonly List<(string, LuaInterop.lua_CFunction)> ms_metaMethods = new List<(string, LuaInterop.lua_CFunction)>();
static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_staticProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
static readonly List<(string, LuaInterop.lua_CFunction)> ms_staticMethods = new List<(string, LuaInterop.lua_CFunction)>();
- static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_instanceProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
- static readonly List<(string, LuaInterop.lua_CFunction)> ms_instanceMethods = new List<(string, LuaInterop.lua_CFunction)>();
internal static void Init()
{
@@ -48,7 +45,7 @@ internal static void Init()
internal static void RegisterInVM(LuaVM p_vm)
{
- p_vm.RegisterClass(typeof(Mathf), null, ms_staticProperties, ms_staticMethods, ms_metaMethods, ms_instanceProperties, ms_instanceMethods);
+ p_vm.RegisterClass(typeof(Mathf), null, ms_staticProperties, ms_staticMethods, null, null, null);
}
// Static properties
diff --git a/CVRLua/Lua/LuaDefs/PhysicsDefs.cs b/CVRLua/Lua/LuaDefs/PhysicsDefs.cs
new file mode 100644
index 0000000..9b3d842
--- /dev/null
+++ b/CVRLua/Lua/LuaDefs/PhysicsDefs.cs
@@ -0,0 +1,604 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace CVRLua.Lua.LuaDefs
+{
+ static class PhysicsDefs
+ {
+ const string c_destroyedCollider = "Collider is destroyed";
+
+ static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_staticProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
+ static readonly List<(string, LuaInterop.lua_CFunction)> ms_staticMethods = new List<(string, LuaInterop.lua_CFunction)>();
+
+ internal static void Init()
+ {
+ ms_staticProperties.Add(("AllLayers", (GetAllLayers, null)));
+ ms_staticProperties.Add(("DefaultRaycastLayers", (GetDefaultRaycastLayers, null)));
+ ms_staticProperties.Add(("gravity", (GetGravity, SetGravity)));
+ ms_staticProperties.Add(("IgnoreRaycastLayer", (GetIgnoreRaycastLayer, null)));
+
+ //ms_staticMethods.Add((nameof(BakeMesh), BakeMesh));
+ ms_staticMethods.Add((nameof(BoxCast), BoxCast));
+ ms_staticMethods.Add((nameof(BoxCastAll), BoxCastAll));
+ ms_staticMethods.Add((nameof(CapsuleCast), CapsuleCast));
+ ms_staticMethods.Add((nameof(CapsuleCastAll), CapsuleCastAll));
+ ms_staticMethods.Add((nameof(CheckBox), CheckBox));
+ ms_staticMethods.Add((nameof(CheckCapsule), CheckCapsule));
+ ms_staticMethods.Add((nameof(CheckSphere), CheckSphere));
+ ms_staticMethods.Add((nameof(ClosestPoint), ClosestPoint));
+ ms_staticMethods.Add((nameof(ComputePenetration), ComputePenetration));
+ ms_staticMethods.Add((nameof(GetIgnoreCollision), GetIgnoreCollision));
+ ms_staticMethods.Add((nameof(GetIgnoreLayerCollision), GetIgnoreLayerCollision));
+ ms_staticMethods.Add((nameof(IgnoreCollision), IgnoreCollision));
+ ms_staticMethods.Add((nameof(Linecast), Linecast));
+ ms_staticMethods.Add((nameof(OverlapBox), OverlapBox));
+ ms_staticMethods.Add((nameof(OverlapCapsule), OverlapCapsule));
+ ms_staticMethods.Add((nameof(OverlapSphere), OverlapSphere));
+ ms_staticMethods.Add((nameof(Raycast), Raycast));
+ ms_staticMethods.Add((nameof(RaycastAll), RaycastAll));
+ ms_staticMethods.Add((nameof(SphereCast), SphereCast));
+ ms_staticMethods.Add((nameof(SphereCastAll), SphereCastAll));
+ }
+
+ internal static void RegisterInVM(LuaVM p_vm)
+ {
+ p_vm.RegisterClass(typeof(Physics), null, ms_staticProperties, ms_staticMethods, null, null, null);
+ }
+
+ // Static properties
+ static int GetAllLayers(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ l_argReader.PushInteger(Physics.AllLayers);
+ return 1;
+ }
+
+ static int GetDefaultRaycastLayers(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ l_argReader.PushInteger(Physics.DefaultRaycastLayers);
+ return 1;
+ }
+
+ static int GetGravity(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ l_argReader.PushObject(new Wrappers.Vector3(Physics.gravity));
+ return 1;
+ }
+ static int SetGravity(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_gravity = null;
+ l_argReader.ReadObject(ref l_gravity);
+ if(!l_argReader.HasErrors())
+ Physics.gravity = l_gravity.m_vec;
+
+ l_argReader.LogError();
+ return 0;
+ }
+
+ static int GetIgnoreRaycastLayer(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ l_argReader.PushInteger(Physics.IgnoreRaycastLayer);
+ return 1;
+ }
+
+ // Static methods
+ static int BoxCast(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_center = null;
+ Wrappers.Vector3 l_halfExtents = null;
+ Wrappers.Vector3 l_dir = null;
+ Wrappers.Quaternion l_orientation = new Wrappers.Quaternion(Quaternion.identity);
+ float l_maxDistance = Mathf.Infinity;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_center);
+ l_argReader.ReadObject(ref l_halfExtents);
+ l_argReader.ReadObject(ref l_dir);
+ l_argReader.ReadNextObject(ref l_orientation);
+ l_argReader.ReadNextNumber(ref l_maxDistance);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushBoolean(Physics.BoxCast(l_center.m_vec, l_halfExtents.m_vec, l_dir.m_vec, l_orientation.m_quat, l_maxDistance, l_layerMask, l_triggerInteraction));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int BoxCastAll(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_center = null;
+ Wrappers.Vector3 l_halfExtents = null;
+ Wrappers.Vector3 l_dir = null;
+ Wrappers.Quaternion l_orientation = new Wrappers.Quaternion(Quaternion.identity);
+ float l_maxDistance = Mathf.Infinity;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_center);
+ l_argReader.ReadObject(ref l_halfExtents);
+ l_argReader.ReadObject(ref l_dir);
+ l_argReader.ReadNextObject(ref l_orientation);
+ l_argReader.ReadNextNumber(ref l_maxDistance);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ {
+ RaycastHit[] l_hits = Physics.BoxCastAll(l_center.m_vec, l_halfExtents.m_vec, l_dir.m_vec, l_orientation.m_quat, l_maxDistance, l_layerMask, l_triggerInteraction);
+ List l_list = new List();
+ foreach(RaycastHit l_hit in l_hits)
+ l_list.Add(new Wrappers.RaycastHit(l_hit));
+ l_list.Sort((a, b) => ((a.m_hit.distance < b.m_hit.distance) ? -1 : 1));
+ l_argReader.PushTable(l_list);
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int CapsuleCast(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_pointA = null;
+ Wrappers.Vector3 l_pointB = null;
+ float l_radius = 0f;
+ Wrappers.Vector3 l_dir = null;
+ float l_maxDistance = Mathf.Infinity;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_pointA);
+ l_argReader.ReadObject(ref l_pointB);
+ l_argReader.ReadNumber(ref l_radius);
+ l_argReader.ReadObject(ref l_dir);
+ l_argReader.ReadNextNumber(ref l_maxDistance);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushBoolean(Physics.CapsuleCast(l_pointA.m_vec, l_pointB.m_vec, l_radius, l_dir.m_vec, l_maxDistance, l_layerMask, l_triggerInteraction));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int CapsuleCastAll(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_pointA = null;
+ Wrappers.Vector3 l_pointB = null;
+ float l_radius = 0f;
+ Wrappers.Vector3 l_dir = null;
+ float l_maxDistance = Mathf.Infinity;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_pointA);
+ l_argReader.ReadObject(ref l_pointB);
+ l_argReader.ReadNumber(ref l_radius);
+ l_argReader.ReadObject(ref l_dir);
+ l_argReader.ReadNextNumber(ref l_maxDistance);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ {
+ RaycastHit[] l_hits = Physics.CapsuleCastAll(l_pointA.m_vec, l_pointB.m_vec, l_radius, l_dir.m_vec, l_maxDistance, l_layerMask, l_triggerInteraction);
+ List l_list = new List();
+ foreach(RaycastHit l_hit in l_hits)
+ l_list.Add(new Wrappers.RaycastHit(l_hit));
+ l_list.Sort((a, b) => ((a.m_hit.distance < b.m_hit.distance) ? -1 : 1));
+ l_argReader.PushTable(l_list);
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int CheckBox(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_center = null;
+ Wrappers.Vector3 l_halfExtents = null;
+ Wrappers.Quaternion l_orientation = new Wrappers.Quaternion(Quaternion.identity);
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_center);
+ l_argReader.ReadObject(ref l_halfExtents);
+ l_argReader.ReadNextObject(ref l_orientation);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushBoolean(Physics.CheckBox(l_center.m_vec, l_halfExtents.m_vec, l_orientation.m_quat, l_layerMask, l_triggerInteraction));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int CheckCapsule(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_pointA = null;
+ Wrappers.Vector3 l_pointB = null;
+ float l_radius = 0f;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_pointA);
+ l_argReader.ReadObject(ref l_pointB);
+ l_argReader.ReadNumber(ref l_radius);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushBoolean(Physics.CheckCapsule(l_pointA.m_vec, l_pointB.m_vec, l_radius, l_layerMask, l_triggerInteraction));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int CheckSphere(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_point = null;
+ float l_radius = 0f;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_point);
+ l_argReader.ReadNumber(ref l_radius);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushBoolean(Physics.CheckSphere(l_point.m_vec, l_radius, l_layerMask, l_triggerInteraction));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int ClosestPoint(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_point = null;
+ Collider l_collider = null;
+ Wrappers.Vector3 l_pos = null;
+ Wrappers.Quaternion l_rot = null;
+ l_argReader.ReadObject(ref l_point);
+ l_argReader.ReadObject(ref l_collider);
+ l_argReader.ReadObject(ref l_pos);
+ l_argReader.ReadObject(ref l_rot);
+ if(!l_argReader.HasErrors())
+ {
+ if(l_collider != null)
+ l_argReader.PushObject(new Wrappers.Vector3(Physics.ClosestPoint(l_point.m_vec, l_collider, l_pos.m_vec, l_rot.m_quat)));
+ else
+ {
+ l_argReader.SetError(c_destroyedCollider);
+ l_argReader.PushBoolean(false);
+ }
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int ComputePenetration(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Collider l_colA = null;
+ Wrappers.Vector3 l_posA = null;
+ Wrappers.Quaternion l_rotA = null;
+ Collider l_colB = null;
+ Wrappers.Vector3 l_posB = null;
+ Wrappers.Quaternion l_rotB = null;
+ l_argReader.ReadObject(ref l_colA);
+ l_argReader.ReadObject(ref l_posA);
+ l_argReader.ReadObject(ref l_rotA);
+ l_argReader.ReadObject(ref l_colB);
+ l_argReader.ReadObject(ref l_posB);
+ l_argReader.ReadObject(ref l_rotB);
+ if(!l_argReader.HasErrors())
+ {
+ if((l_colA != null) && (l_colB != null))
+ {
+ bool l_result = Physics.ComputePenetration(l_colA, l_posA.m_vec, l_rotA.m_quat, l_colB, l_posB.m_vec, l_rotB.m_quat, out Vector3 l_dir, out float l_dist);
+ if(l_result)
+ {
+ l_argReader.PushObject(new Wrappers.Vector3(l_dir));
+ l_argReader.PushNumber(l_dist);
+ }
+ else
+ l_argReader.PushBoolean(false);
+ }
+ else
+ {
+ l_argReader.SetError(c_destroyedCollider);
+ l_argReader.PushBoolean(false);
+ }
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int GetIgnoreCollision(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Collider l_colA = null;
+ Collider l_colB = null;
+ l_argReader.ReadObject(ref l_colA);
+ l_argReader.ReadObject(ref l_colB);
+ if(!l_argReader.HasErrors())
+ {
+ if((l_colA != null) && (l_colB != null))
+ l_argReader.PushBoolean(Physics.GetIgnoreCollision(l_colA, l_colB));
+ else
+ {
+ l_argReader.SetError(c_destroyedCollider);
+ l_argReader.PushBoolean(false);
+ }
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int GetIgnoreLayerCollision(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ int l_layerA = 0;
+ int l_layerB = 0;
+ l_argReader.ReadInteger(ref l_layerA);
+ l_argReader.ReadInteger(ref l_layerB);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushBoolean(Physics.GetIgnoreLayerCollision(l_layerA, l_layerB));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int IgnoreCollision(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Collider l_colA = null;
+ Collider l_colB = null;
+ l_argReader.ReadObject(ref l_colA);
+ l_argReader.ReadObject(ref l_colB);
+ if(!l_argReader.HasErrors())
+ {
+ if((l_colA != null) && (l_colB != null))
+ {
+ Physics.IgnoreCollision(l_colA, l_colB);
+ l_argReader.PushBoolean(true);
+ }
+ else
+ {
+ l_argReader.SetError(c_destroyedCollider);
+ l_argReader.PushBoolean(false);
+ }
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int Linecast(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_pointA = null;
+ Wrappers.Vector3 l_pointB = null;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_pointA);
+ l_argReader.ReadObject(ref l_pointB);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushBoolean(Physics.Linecast(l_pointA.m_vec, l_pointB.m_vec, l_layerMask, l_triggerInteraction));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int OverlapBox(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_center = null;
+ Wrappers.Vector3 l_halfExtents = null;
+ Wrappers.Quaternion l_orientation = new Wrappers.Quaternion(Quaternion.identity);
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_center);
+ l_argReader.ReadObject(ref l_halfExtents);
+ l_argReader.ReadNextObject(ref l_orientation);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushTable(Physics.OverlapBox(l_center.m_vec, l_halfExtents.m_vec, l_orientation.m_quat, l_layerMask, l_triggerInteraction));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int OverlapCapsule(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_pointA = null;
+ Wrappers.Vector3 l_pointB = null;
+ float l_radius = 0f;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_pointA);
+ l_argReader.ReadObject(ref l_pointB);
+ l_argReader.ReadNumber(ref l_radius);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushTable(Physics.OverlapCapsule(l_pointA.m_vec, l_pointB.m_vec, l_radius, l_layerMask, l_triggerInteraction));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int OverlapSphere(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_point = null;
+ float l_radius = 0f;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_point);
+ l_argReader.ReadNumber(ref l_radius);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushTable(Physics.OverlapSphere(l_point.m_vec, l_radius, l_layerMask, l_triggerInteraction));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int Raycast(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_origin = null;
+ Wrappers.Vector3 l_dir = null;
+ float l_maxDist = Mathf.Infinity;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_origin);
+ l_argReader.ReadObject(ref l_dir);
+ l_argReader.ReadNextNumber(ref l_maxDist);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushBoolean(Physics.Raycast(l_origin.m_vec, l_dir.m_vec, l_maxDist, l_layerMask, l_triggerInteraction));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int RaycastAll(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_origin = null;
+ Wrappers.Vector3 l_dir = null;
+ float l_maxDist = Mathf.Infinity;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_origin);
+ l_argReader.ReadObject(ref l_dir);
+ l_argReader.ReadNextNumber(ref l_maxDist);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ {
+ RaycastHit[] l_hits = Physics.RaycastAll(l_origin.m_vec, l_dir.m_vec, l_maxDist, l_layerMask, l_triggerInteraction);
+ List l_list = new List();
+ foreach(RaycastHit l_hit in l_hits)
+ l_list.Add(new Wrappers.RaycastHit(l_hit));
+ l_list.Sort((a, b) => ((a.m_hit.distance < b.m_hit.distance) ? -1 : 1));
+ l_argReader.PushTable(l_list);
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int SphereCast(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_origin = null;
+ float l_radius = 0f;
+ Wrappers.Vector3 l_dir = null;
+ float l_maxDist = Mathf.Infinity;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_origin);
+ l_argReader.ReadNumber(ref l_radius);
+ l_argReader.ReadObject(ref l_dir);
+ l_argReader.ReadNextNumber(ref l_maxDist);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ {
+ bool l_result = Physics.SphereCast(l_origin.m_vec, l_radius, l_dir.m_vec, out RaycastHit l_hit, l_maxDist, l_layerMask, l_triggerInteraction);
+ if(l_result)
+ l_argReader.PushObject(new Wrappers.RaycastHit(l_hit));
+ else
+ l_argReader.PushBoolean(false);
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ static int SphereCastAll(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.Vector3 l_origin = null;
+ float l_radius = 0f;
+ Wrappers.Vector3 l_dir = null;
+ float l_maxDist = Mathf.Infinity;
+ int l_layerMask = Physics.DefaultRaycastLayers;
+ QueryTriggerInteraction l_triggerInteraction = QueryTriggerInteraction.UseGlobal;
+ l_argReader.ReadObject(ref l_origin);
+ l_argReader.ReadNumber(ref l_radius);
+ l_argReader.ReadObject(ref l_dir);
+ l_argReader.ReadNextNumber(ref l_maxDist);
+ l_argReader.ReadNextInteger(ref l_layerMask);
+ l_argReader.ReadNextEnum(ref l_triggerInteraction);
+ if(!l_argReader.HasErrors())
+ {
+ RaycastHit[] l_hits = Physics.SphereCastAll(l_origin.m_vec, l_radius, l_dir.m_vec, l_maxDist, l_layerMask, l_triggerInteraction);
+ List l_list = new List();
+ foreach(RaycastHit l_hit in l_hits)
+ l_list.Add(new Wrappers.RaycastHit(l_hit));
+ l_list.Sort((a, b) => ((a.m_hit.distance < b.m_hit.distance) ? -1 : 1));
+ l_argReader.PushTable(l_list);
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+ }
+}
diff --git a/CVRLua/Lua/LuaDefs/RaycastHitDefs.cs b/CVRLua/Lua/LuaDefs/RaycastHitDefs.cs
new file mode 100644
index 0000000..4781ee7
--- /dev/null
+++ b/CVRLua/Lua/LuaDefs/RaycastHitDefs.cs
@@ -0,0 +1,249 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace CVRLua.Lua.LuaDefs
+{
+ class RaycastHitDefs
+ {
+ static readonly List<(string, LuaInterop.lua_CFunction)> ms_metaMethods = new List<(string, LuaInterop.lua_CFunction)>();
+ static readonly List<(string, LuaInterop.lua_CFunction)> ms_staticMethods = new List<(string, LuaInterop.lua_CFunction)>();
+ static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_instanceProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
+
+ internal static void Init()
+ {
+ ms_staticMethods.Add((nameof(IsRaycastHit), IsRaycastHit));
+
+ ms_metaMethods.Add(("__eq", Equal));
+ ms_metaMethods.Add(("__tostring", ToString));
+
+ //ms_instanceProperties.Add(("articulationBody", (?,?)));
+ ms_instanceProperties.Add(("barycentricCoordinate", (GetBarycentricCoordinate, null)));
+ ms_instanceProperties.Add(("collider", (GetCollider, null)));
+ ms_instanceProperties.Add(("distance", (GetDistance, null)));
+ ms_instanceProperties.Add(("lightmapCoord", (GetLightmapCoord, null)));
+ ms_instanceProperties.Add(("normal", (GetNormal, null)));
+ ms_instanceProperties.Add(("point", (GetPoint, null)));
+ ms_instanceProperties.Add(("rigidbody", (GetRigidbody, null)));
+ ms_instanceProperties.Add(("textureCoord", (GetTextureCoord, null)));
+ ms_instanceProperties.Add(("textureCoord2", (GetTextureCoord2, null)));
+ ms_instanceProperties.Add(("transform", (GetTransform, null)));
+ ms_instanceProperties.Add(("triangleIndex", (GetTriangleIndex, null)));
+ }
+
+ internal static void RegisterInVM(LuaVM p_vm)
+ {
+ p_vm.RegisterClass(typeof(RaycastHit), null, null, ms_staticMethods, ms_metaMethods, ms_instanceProperties, null);
+ }
+
+ // Static methods
+ static int IsRaycastHit(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadNextObject(ref l_hit);
+ l_argReader.PushBoolean(l_hit != null);
+ return l_argReader.GetReturnValue();
+ }
+
+ // Metamethods
+ static int Equal(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hitA = null;
+ Wrappers.RaycastHit l_hitB = null;
+ l_argReader.ReadObject(ref l_hitA);
+ l_argReader.ReadObject(ref l_hitB);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushBoolean(l_hitA == l_hitB);
+ else
+ l_argReader.PushBoolean(false);
+
+ return l_argReader.GetReturnValue();
+ }
+
+ static int ToString(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_col = null;
+ l_argReader.ReadObject(ref l_col);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushString(l_col.ToString());
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return l_argReader.GetReturnValue();
+ }
+
+ // Instance properties
+ static int GetBarycentricCoordinate(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadObject(ref l_hit);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushObject(new Wrappers.Vector3(l_hit.m_hit.barycentricCoordinate));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return 1;
+ }
+
+ static int GetCollider(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadObject(ref l_hit);
+ if(!l_argReader.HasErrors())
+ {
+ if(l_hit.m_hit.collider != null)
+ l_argReader.PushObject(l_hit.m_hit.collider);
+ else
+ l_argReader.PushBoolean(false);
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return 1;
+ }
+
+ static int GetDistance(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadObject(ref l_hit);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushNumber(l_hit.m_hit.distance);
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return 1;
+ }
+
+ static int GetLightmapCoord(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadObject(ref l_hit);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushObject(new Wrappers.Vector2(l_hit.m_hit.lightmapCoord));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return 1;
+ }
+
+ static int GetNormal(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadObject(ref l_hit);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushObject(new Wrappers.Vector3(l_hit.m_hit.normal));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return 1;
+ }
+
+ static int GetPoint(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadObject(ref l_hit);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushObject(new Wrappers.Vector3(l_hit.m_hit.point));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return 1;
+ }
+
+ static int GetRigidbody(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadObject(ref l_hit);
+ if(!l_argReader.HasErrors())
+ {
+ if(l_hit.m_hit.rigidbody != null)
+ l_argReader.PushObject(l_hit.m_hit.rigidbody);
+ else
+ l_argReader.PushBoolean(false);
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return 1;
+ }
+
+ static int GetTextureCoord(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadObject(ref l_hit);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushObject(new Wrappers.Vector2(l_hit.m_hit.textureCoord));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return 1;
+ }
+
+ static int GetTextureCoord2(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadObject(ref l_hit);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushObject(new Wrappers.Vector2(l_hit.m_hit.textureCoord2));
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return 1;
+ }
+
+ static int GetTransform(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadObject(ref l_hit);
+ if(!l_argReader.HasErrors())
+ {
+ if(l_hit.m_hit.transform != null)
+ l_argReader.PushObject(l_hit.m_hit.transform);
+ else
+ l_argReader.PushBoolean(false);
+ }
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return 1;
+ }
+
+ static int GetTriangleIndex(IntPtr p_state)
+ {
+ var l_argReader = new LuaArgReader(p_state);
+ Wrappers.RaycastHit l_hit = null;
+ l_argReader.ReadObject(ref l_hit);
+ if(!l_argReader.HasErrors())
+ l_argReader.PushInteger(l_hit.m_hit.triangleIndex);
+ else
+ l_argReader.PushBoolean(false);
+
+ l_argReader.LogError();
+ return 1;
+ }
+ }
+}
diff --git a/CVRLua/Lua/LuaDefs/RigidbodyDefs.cs b/CVRLua/Lua/LuaDefs/RigidbodyDefs.cs
index 40c1d56..e95fae0 100644
--- a/CVRLua/Lua/LuaDefs/RigidbodyDefs.cs
+++ b/CVRLua/Lua/LuaDefs/RigidbodyDefs.cs
@@ -996,7 +996,7 @@ static int AddExplosionForce(IntPtr p_state)
l_argReader.ReadNumber(ref l_force);
l_argReader.ReadObject(ref l_pos);
l_argReader.ReadNumber(ref l_radius);
- l_argReader.ReadNextNumber(ref l_radius);
+ l_argReader.ReadNextNumber(ref l_upwards);
l_argReader.ReadNextEnum(ref l_mode);
if(!l_argReader.HasErrors())
{
diff --git a/CVRLua/Lua/LuaDefs/TimeDefs.cs b/CVRLua/Lua/LuaDefs/TimeDefs.cs
index 6a2aa52..8fba596 100644
--- a/CVRLua/Lua/LuaDefs/TimeDefs.cs
+++ b/CVRLua/Lua/LuaDefs/TimeDefs.cs
@@ -6,11 +6,7 @@ namespace CVRLua.Lua.LuaDefs
{
static class TimeDefs
{
- static readonly List<(string, LuaInterop.lua_CFunction)> ms_metaMethods = new List<(string, LuaInterop.lua_CFunction)>();
static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_staticProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
- static readonly List<(string, LuaInterop.lua_CFunction)> ms_staticMethods = new List<(string, LuaInterop.lua_CFunction)>();
- static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_instanceProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
- static readonly List<(string, LuaInterop.lua_CFunction)> ms_instanceMethods = new List<(string, LuaInterop.lua_CFunction)>();
internal static void Init()
{
@@ -33,7 +29,7 @@ internal static void Init()
internal static void RegisterInVM(LuaVM p_vm)
{
- p_vm.RegisterClass(typeof(Time), null, ms_staticProperties, ms_staticMethods, ms_metaMethods, ms_instanceProperties, ms_instanceMethods);
+ p_vm.RegisterClass(typeof(Time), null, ms_staticProperties, null, null, null, null);
}
// static properties
diff --git a/CVRLua/Lua/LuaInterop.cs b/CVRLua/Lua/LuaInterop.cs
index aba6a29..0d718bb 100644
--- a/CVRLua/Lua/LuaInterop.cs
+++ b/CVRLua/Lua/LuaInterop.cs
@@ -260,5 +260,10 @@ public static void lua_remove(IntPtr L, int idx)
[DllImport(ms_binaryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void lua_seti(IntPtr L, int idx, long n);
+
+ [DllImport(ms_binaryName, CallingConvention = CallingConvention.Cdecl)]
+ public static extern int luaL_loadbufferx(IntPtr L, byte[] buff, long sz, string name, string mode);
+
+ public static int luaL_loadbuffer(IntPtr L, ref byte[] s, long sz, string n) => luaL_loadbufferx(L, s, sz, n, "bt");
}
}
diff --git a/CVRLua/Lua/LuaVM.cs b/CVRLua/Lua/LuaVM.cs
index 15b369d..4317687 100644
--- a/CVRLua/Lua/LuaVM.cs
+++ b/CVRLua/Lua/LuaVM.cs
@@ -100,6 +100,15 @@ internal void Execute(string p_script)
}
}
+ internal void Execute(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))
+ {
+ LuaLogger.Log(LuaInterop.lua_tostring(m_state, -1));
+ LuaInterop.lua_pop(m_state, 1);
+ }
+ }
+
// Objects push/get
public void PushObject(object p_obj)
{
diff --git a/CVRLua/LuaHandler.cs b/CVRLua/LuaHandler.cs
index ccebffc..9992c7a 100644
--- a/CVRLua/LuaHandler.cs
+++ b/CVRLua/LuaHandler.cs
@@ -49,7 +49,9 @@ internal static void Init()
Lua.LuaDefs.ContactPointDefs.Init();
Lua.LuaDefs.GameObjectDefs.Init();
Lua.LuaDefs.MathfDefs.Init();
+ Lua.LuaDefs.PhysicsDefs.Init();
Lua.LuaDefs.QuaternionDefs.Init();
+ Lua.LuaDefs.RaycastHitDefs.Init();
Lua.LuaDefs.RigidbodyDefs.Init();
Lua.LuaDefs.TimeDefs.Init();
Lua.LuaDefs.TransformDefs.Init();
@@ -97,7 +99,9 @@ internal LuaHandler(string p_name = "")
Lua.LuaDefs.ContactPointDefs.RegisterInVM(m_vm);
Lua.LuaDefs.GameObjectDefs.RegisterInVM(m_vm);
Lua.LuaDefs.MathfDefs.RegisterInVM(m_vm);
+ Lua.LuaDefs.PhysicsDefs.RegisterInVM(m_vm);
Lua.LuaDefs.QuaternionDefs.RegisterInVM(m_vm);
+ Lua.LuaDefs.RaycastHitDefs.RegisterInVM(m_vm);
Lua.LuaDefs.RigidbodyDefs.RegisterInVM(m_vm);
Lua.LuaDefs.TimeDefs.RegisterInVM(m_vm);
Lua.LuaDefs.TransformDefs.RegisterInVM(m_vm);
@@ -130,6 +134,10 @@ public void Execute(string p_code)
{
m_vm.Execute(p_code);
}
+ public void Execute(ref byte[] p_data)
+ {
+ m_vm.Execute(ref p_data);
+ }
public void CallEvent(ScriptEvent p_event, params object[] p_args)
{
diff --git a/CVRLua/LuaScript.cs b/CVRLua/LuaScript.cs
index a046625..50e57f1 100644
--- a/CVRLua/LuaScript.cs
+++ b/CVRLua/LuaScript.cs
@@ -42,7 +42,10 @@ void Awake()
}
foreach(var l_script in Scripts)
- m_luaHandler.Execute(l_script.text);
+ {
+ byte[] l_data = l_script.bytes;
+ m_luaHandler.Execute(ref l_data);
+ }
m_luaHandler.ParseEvents();
m_luaHandler.CallEvent(LuaHandler.ScriptEvent.Start);
diff --git a/CVRLua/Wrappers/RaycastHit.cs b/CVRLua/Wrappers/RaycastHit.cs
new file mode 100644
index 0000000..ac6f547
--- /dev/null
+++ b/CVRLua/Wrappers/RaycastHit.cs
@@ -0,0 +1,12 @@
+namespace CVRLua.Wrappers
+{
+ class RaycastHit
+ {
+ public UnityEngine.RaycastHit m_hit;
+
+ public RaycastHit(UnityEngine.RaycastHit p_hit)
+ {
+ m_hit = p_hit;
+ }
+ }
+}