finally Userdata() syntax, no more nasty CreateUserdata or Userdata.Create
This commit is contained in:
@@ -9,6 +9,8 @@ using System.Threading.Tasks;
|
||||
using Barotrauma.Items.Components;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using MoonSharp.Interpreter.Interop;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -174,6 +176,37 @@ namespace Barotrauma
|
||||
return value * 2;
|
||||
}
|
||||
|
||||
// messy solution
|
||||
private object HandleCall(object arg1, ScriptExecutionContext arg2, CallbackArguments arg3)
|
||||
{
|
||||
var what = arg3.RawGet(0, true);
|
||||
|
||||
var code = "return " + what.UserData.Descriptor.Type.Name + ".__new(";
|
||||
|
||||
var tbl = new Table(lua);
|
||||
tbl[what.UserData.Descriptor.Type.Name] = what;
|
||||
|
||||
for(var i=1; i < arg3.Count; i++)
|
||||
{
|
||||
if (i == arg3.Count - 1)
|
||||
code = code + "arg" + i;
|
||||
else
|
||||
code = code + "arg" + i + ",";
|
||||
|
||||
tbl["arg" + i] = arg3.RawGet(i, true);
|
||||
}
|
||||
|
||||
code = code + ")";
|
||||
|
||||
return lua.DoString(code, tbl);
|
||||
}
|
||||
|
||||
private void AddCallMetaMember(IUserDataDescriptor IUDD)
|
||||
{
|
||||
var descriptor = (StandardUserDataDescriptor)IUDD;
|
||||
descriptor.AddMetaMember("__call", new ObjectCallbackMemberDescriptor("__call", HandleCall));
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
|
||||
@@ -198,7 +231,6 @@ namespace Barotrauma
|
||||
|
||||
UserData.RegisterType<TraitorMessageType>();
|
||||
UserData.RegisterType<JobPrefab>();
|
||||
UserData.RegisterType<CharacterInfo>();
|
||||
UserData.RegisterType<Rectangle>();
|
||||
UserData.RegisterType<Point>();
|
||||
UserData.RegisterType<Level.InterestingPosition>();
|
||||
@@ -220,9 +252,6 @@ namespace Barotrauma
|
||||
UserData.RegisterType<LuaTimer>();
|
||||
UserData.RegisterType<LuaFile>();
|
||||
UserData.RegisterType<LuaNetworking>();
|
||||
UserData.RegisterType<Vector2>();
|
||||
UserData.RegisterType<Vector3>();
|
||||
UserData.RegisterType<Vector4>();
|
||||
UserData.RegisterType<CauseOfDeathType>();
|
||||
UserData.RegisterType<AfflictionPrefab>();
|
||||
UserData.RegisterType<Affliction>();
|
||||
@@ -239,7 +268,6 @@ namespace Barotrauma
|
||||
UserData.RegisterType<MapEntityPrefab>();
|
||||
UserData.RegisterType<CauseOfDeath>();
|
||||
UserData.RegisterType<CharacterTeamType>();
|
||||
UserData.RegisterType<Signal>();
|
||||
UserData.RegisterType<Connection>();
|
||||
UserData.RegisterType<ItemComponent>();
|
||||
UserData.RegisterType<WifiComponent>();
|
||||
@@ -288,6 +316,13 @@ namespace Barotrauma
|
||||
UserData.RegisterType<ClientPacketHeader>();
|
||||
UserData.RegisterType<DeliveryMethod>();
|
||||
|
||||
AddCallMetaMember(UserData.RegisterType<Vector2>());
|
||||
AddCallMetaMember(UserData.RegisterType<Vector3>());
|
||||
AddCallMetaMember(UserData.RegisterType<Vector4>());
|
||||
AddCallMetaMember(UserData.RegisterType<CharacterInfo>());
|
||||
AddCallMetaMember(UserData.RegisterType<Signal>());
|
||||
|
||||
|
||||
lua = new Script(CoreModules.Preset_SoftSandbox);
|
||||
|
||||
lua.Options.DebugPrint = PrintMessage;
|
||||
@@ -337,10 +372,7 @@ namespace Barotrauma
|
||||
lua.Globals["CharacterTeamType"] = UserData.CreateStatic<CharacterTeamType>();
|
||||
lua.Globals["Vector2"] = UserData.CreateStatic<Vector2>();
|
||||
lua.Globals["Vector3"] = UserData.CreateStatic<Vector3>();
|
||||
lua.Globals["Vector4"] = UserData.CreateStatic<Vector3>();
|
||||
lua.Globals["CreateVector2"] = (Func<float, float, Vector2>)CreateVector2;
|
||||
lua.Globals["CreateVector3"] = (Func<float, float, float, Vector3>)CreateVector3;
|
||||
lua.Globals["CreateVector4"] = (Func<float, float, float, float, Vector4>)CreateVector4;
|
||||
lua.Globals["Vector4"] = UserData.CreateStatic<Vector4>();
|
||||
lua.Globals["ChatMessage"] = UserData.CreateStatic<ChatMessage>();
|
||||
lua.Globals["Hull"] = UserData.CreateStatic<Hull>();
|
||||
lua.Globals["InvSlotType"] = UserData.CreateStatic<InvSlotType>();
|
||||
@@ -352,6 +384,11 @@ namespace Barotrauma
|
||||
lua.Globals["ClientPacketHeader"] = UserData.CreateStatic<ClientPacketHeader>();
|
||||
lua.Globals["ServerPacketHeader"] = UserData.CreateStatic<ServerPacketHeader>();
|
||||
|
||||
// obsolete
|
||||
lua.Globals["CreateVector2"] = (Func<float, float, Vector2>)CreateVector2;
|
||||
lua.Globals["CreateVector3"] = (Func<float, float, float, Vector3>)CreateVector3;
|
||||
lua.Globals["CreateVector4"] = (Func<float, float, float, float, Vector4>)CreateVector4;
|
||||
|
||||
bool isServer = true;
|
||||
|
||||
#if SERVER
|
||||
@@ -385,7 +422,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public LuaSetup()
|
||||
{
|
||||
|
||||
|
||||
@@ -17,4 +17,4 @@ local CharacterInfo = {}
|
||||
-- local vsauce = CharacterInfo.__new("human", "VSAUCE HERE")
|
||||
-- local character = Character.Create(vsauce, Vector2.__new(0, 0), "some random characters")
|
||||
-- print(character)
|
||||
function CharacterInfo.__new(speciesName, name, jobPrefab, ragdollFileName, variant, randSync, npcIdentifier) end
|
||||
function CharacterInfo(speciesName, name, jobPrefab, ragdollFileName, variant, randSync, npcIdentifier) end
|
||||
+1
-1
@@ -13,7 +13,7 @@ Signal = {}
|
||||
--- Instantiates a new Signal.
|
||||
-- @treturn Signal
|
||||
-- @realm shared
|
||||
function Signal.__new(stringValue, stepsTaken, characterSender, itemSource, power, strength) end
|
||||
function Signal(stringValue, stepsTaken, characterSender, itemSource, power, strength) end
|
||||
|
||||
---
|
||||
-- value, String value of the signal.
|
||||
|
||||
@@ -8,7 +8,6 @@ These are the XNA Vectors, you can find all the functions and fields here: <br>
|
||||
<a href="https://docs.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/bb199679(v=xnagamestudio.35)">XNA Vector4</a> <br>
|
||||
|
||||
Access them via Vector2.\*, Vector3.\*, Vector4.\* <br>
|
||||
CreateVector2, CreateVector3, CreateVector4 are globals.
|
||||
]]
|
||||
-- @code Vectors
|
||||
|
||||
@@ -19,14 +18,14 @@ local Vector4 = {}
|
||||
--- Create Vector2
|
||||
-- @treturn Vector2
|
||||
-- @realm shared
|
||||
function Vector2.__new(x, y) end
|
||||
function Vector2(X, Y) end
|
||||
|
||||
--- Create Vector3
|
||||
-- @treturn Vector3
|
||||
-- @realm shared
|
||||
function Vector3.__new(x, y, z) end
|
||||
function Vector3(X, Y, Z) end
|
||||
|
||||
--- Create Vector4
|
||||
-- @treturn Vector4
|
||||
-- @realm shared
|
||||
function Vector4.__new(x, y, z, w) end
|
||||
function Vector4(X, Y, Z, W) end
|
||||
Reference in New Issue
Block a user