Skip to content

Commit

Permalink
Physics and RaycastHit defs
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed May 31, 2023
1 parent d9e30ef commit 920b1f2
Show file tree
Hide file tree
Showing 15 changed files with 917 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CVRLua/CVRLua.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
<Compile Include="Lua\LuaDefs\CVRInteractableDefs.cs" />
<Compile Include="Lua\LuaDefs\CVRPickupObjectDefs.cs" />
<Compile Include="Lua\LuaDefs\CVRVideoPlayerDefs.cs" />
<Compile Include="Lua\LuaDefs\PhysicsDefs.cs" />
<Compile Include="Lua\LuaDefs\RaycastHitDefs.cs" />
<Compile Include="Lua\LuaDefs\RigidbodyDefs.cs" />
<Compile Include="Lua\LuaDefs\TerrainColliderDefs.cs" />
<Compile Include="Lua\LuaDefs\WheelColliderDefs.cs" />
Expand Down Expand Up @@ -134,6 +136,7 @@
<Compile Include="Wrappers\ContactPoint.cs" />
<Compile Include="Wrappers\LocalPlayer.cs" />
<Compile Include="Wrappers\Quaternion.cs" />
<Compile Include="Wrappers\RaycastHit.cs" />
<Compile Include="Wrappers\Vector2.cs" />
<Compile Include="Wrappers\Vector4.cs" />
<Compile Include="Wrappers\Vector3.cs" />
Expand Down
3 changes: 1 addition & 2 deletions CVRLua/Lua/LuaDefs/CollisionDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>();
Expand All @@ -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
Expand Down
19 changes: 17 additions & 2 deletions CVRLua/Lua/LuaDefs/ContactPointDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>();
Expand All @@ -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)));
Expand All @@ -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
Expand All @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions CVRLua/Lua/LuaDefs/DateTimeDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions CVRLua/Lua/LuaDefs/LocalPlayerDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>();
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions CVRLua/Lua/LuaDefs/MathfDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 920b1f2

Please sign in to comment.