Minor refactor for LuaUserData.lua
This commit is contained in:
@@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
local compatibilityLib = {}
|
local compatibilityLib = {}
|
||||||
|
|
||||||
LuaUserData.AddMethod(LuaUserData.RegisterType("Barotrauma.LuaUserData"), "AddCallMetaMember", function (v)
|
|
||||||
print("AddCallMetaMember is deprecated, use debug.setmetatable instead.")
|
|
||||||
end)
|
|
||||||
|
|
||||||
local networking = LuaUserData.RegisterType("Barotrauma.LuaCsNetworking")
|
local networking = LuaUserData.RegisterType("Barotrauma.LuaCsNetworking")
|
||||||
|
|
||||||
LuaUserData.AddMethod(networking, "RequestGetHTTP", Networking.HttpGet)
|
LuaUserData.AddMethod(networking, "RequestGetHTTP", Networking.HttpGet)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
local defaultLib = {}
|
local defaultLib = {}
|
||||||
|
|
||||||
local CreateStatic = LuaSetup.CreateStatic
|
local CreateStatic = LuaSetup.LuaUserData.CreateStatic
|
||||||
local CreateEnum = LuaUserData.CreateEnumTable
|
local CreateEnum = LuaSetup.LuaUserData.CreateEnumTable
|
||||||
|
|
||||||
local localizedStrings = {
|
local localizedStrings = {
|
||||||
"LocalizedString", "LimitLString", "WrappedLString", "AddedPunctuationLString", "CapitalizeLString", "ConcatLString", "FallbackLString", "FormattedLString", "InputTypeLString", "JoinLString", "LowerLString", "RawLString", "ReplaceLString", "ServerMsgLString", "SplitLString", "TagLString", "TrimLString", "UpperLString", "StripRichTagsLString",
|
"LocalizedString", "LimitLString", "WrappedLString", "AddedPunctuationLString", "CapitalizeLString", "ConcatLString", "FallbackLString", "FormattedLString", "InputTypeLString", "JoinLString", "LowerLString", "RawLString", "ReplaceLString", "ServerMsgLString", "SplitLString", "TagLString", "TrimLString", "UpperLString", "StripRichTagsLString",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
local defaultLib = {}
|
local defaultLib = {}
|
||||||
|
|
||||||
local CreateStatic = LuaSetup.CreateStatic
|
local CreateStatic = LuaSetup.LuaUserData.CreateStatic
|
||||||
local CreateEnum = LuaUserData.CreateEnumTable
|
local CreateEnum = LuaSetup.LuaUserData.CreateEnumTable
|
||||||
|
|
||||||
local localizedStrings = {
|
local localizedStrings = {
|
||||||
"LocalizedString", "AddedPunctuationLString", "CapitalizeLString", "ConcatLString", "FallbackLString", "FormattedLString", "InputTypeLString", "JoinLString", "LowerLString", "RawLString", "ReplaceLString", "ServerMsgLString", "SplitLString", "TagLString", "TrimLString", "UpperLString", "StripRichTagsLString",
|
"LocalizedString", "AddedPunctuationLString", "CapitalizeLString", "ConcatLString", "FallbackLString", "FormattedLString", "InputTypeLString", "JoinLString", "LowerLString", "RawLString", "ReplaceLString", "ServerMsgLString", "SplitLString", "TagLString", "TrimLString", "UpperLString", "StripRichTagsLString",
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
local defaultLib = {}
|
local defaultLib = {}
|
||||||
|
|
||||||
local AddCallMetaTable = LuaSetup.AddCallMetaTable
|
local AddCallMetaTable = LuaSetup.LuaUserData.AddCallMetaTable
|
||||||
local CreateStatic = LuaSetup.CreateStatic
|
local CreateStatic = LuaSetup.LuaUserData.CreateStatic
|
||||||
local CreateEnum = LuaUserData.CreateEnumTable
|
local CreateEnum = LuaSetup.LuaUserData.CreateEnumTable
|
||||||
|
|
||||||
require("DefaultLib/Utils/SteamApi")
|
require("DefaultLib/Utils/SteamApi")
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
local Register = LuaSetup.Register
|
local Register = LuaSetup.LuaUserData.RegisterType
|
||||||
local RegisterBarotrauma = LuaSetup.RegisterBarotrauma
|
local RegisterBarotrauma = LuaSetup.LuaUserData.RegisterTypeBarotrauma
|
||||||
|
|
||||||
local localizedStrings = {
|
local localizedStrings = {
|
||||||
"LocalizedString", "LimitLString", "WrappedLString", "AddedPunctuationLString", "CapitalizeLString", "ConcatLString", "FallbackLString", "FormattedLString", "InputTypeLString", "JoinLString", "LowerLString", "RawLString", "ReplaceLString", "ServerMsgLString", "SplitLString", "TagLString", "TrimLString", "UpperLString", "StripRichTagsLString",
|
"LocalizedString", "LimitLString", "WrappedLString", "AddedPunctuationLString", "CapitalizeLString", "ConcatLString", "FallbackLString", "FormattedLString", "InputTypeLString", "JoinLString", "LowerLString", "RawLString", "ReplaceLString", "ServerMsgLString", "SplitLString", "TagLString", "TrimLString", "UpperLString", "StripRichTagsLString",
|
||||||
@@ -65,11 +65,18 @@ RegisterBarotrauma("GUIDropDown")
|
|||||||
RegisterBarotrauma("GUINumberInput")
|
RegisterBarotrauma("GUINumberInput")
|
||||||
RegisterBarotrauma("GUIMessage")
|
RegisterBarotrauma("GUIMessage")
|
||||||
RegisterBarotrauma("GUIMessageBox")
|
RegisterBarotrauma("GUIMessageBox")
|
||||||
RegisterBarotrauma("GUIFont")
|
|
||||||
RegisterBarotrauma("GUIFontPrefab")
|
|
||||||
RegisterBarotrauma("GUIColorPicker")
|
RegisterBarotrauma("GUIColorPicker")
|
||||||
RegisterBarotrauma("GUIProgressBar")
|
RegisterBarotrauma("GUIProgressBar")
|
||||||
RegisterBarotrauma("GUICustomComponent")
|
RegisterBarotrauma("GUICustomComponent")
|
||||||
RegisterBarotrauma("GUIScissorComponent")
|
RegisterBarotrauma("GUIScissorComponent")
|
||||||
|
RegisterBarotrauma("GUIComponentStyle")
|
||||||
|
RegisterBarotrauma("GUIFontPrefab")
|
||||||
|
RegisterBarotrauma("GUIFont")
|
||||||
|
RegisterBarotrauma("GUISpritePrefab")
|
||||||
|
RegisterBarotrauma("GUISprite")
|
||||||
|
RegisterBarotrauma("GUISpriteSheetPrefab")
|
||||||
|
RegisterBarotrauma("GUISpriteSheet")
|
||||||
|
RegisterBarotrauma("GUICursorPrefab")
|
||||||
|
RegisterBarotrauma("GUICursor")
|
||||||
|
|
||||||
RegisterBarotrauma("Inventory+SlotReference")
|
RegisterBarotrauma("Inventory+SlotReference")
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
local Register = LuaSetup.Register
|
local Register = LuaSetup.LuaUserData.RegisterType
|
||||||
local RegisterBarotrauma = LuaSetup.RegisterBarotrauma
|
local RegisterBarotrauma = LuaSetup.LuaUserData.RegisterTypeBarotrauma
|
||||||
|
|
||||||
|
|
||||||
local localizedStrings = {
|
local localizedStrings = {
|
||||||
@@ -10,6 +10,8 @@ for key, value in pairs(localizedStrings) do
|
|||||||
RegisterBarotrauma(value)
|
RegisterBarotrauma(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
RegisterBarotrauma("Character+TeamChangeEventData")
|
||||||
|
|
||||||
RegisterBarotrauma("Networking.GameServer")
|
RegisterBarotrauma("Networking.GameServer")
|
||||||
|
|
||||||
RegisterBarotrauma("Networking.ServerPeer")
|
RegisterBarotrauma("Networking.ServerPeer")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
local Register = LuaSetup.Register
|
local Register = LuaSetup.LuaUserData.RegisterType
|
||||||
local RegisterBarotrauma = LuaSetup.RegisterBarotrauma
|
local RegisterBarotrauma = LuaSetup.LuaUserData.RegisterTypeBarotrauma
|
||||||
|
|
||||||
Register("System.TimeSpan")
|
Register("System.TimeSpan")
|
||||||
Register("System.Exception")
|
Register("System.Exception")
|
||||||
@@ -8,6 +8,9 @@ RegisterBarotrauma("LuaByte")
|
|||||||
RegisterBarotrauma("LuaUShort")
|
RegisterBarotrauma("LuaUShort")
|
||||||
RegisterBarotrauma("LuaFloat")
|
RegisterBarotrauma("LuaFloat")
|
||||||
|
|
||||||
|
RegisterBarotrauma("Range`1[System.Single]")
|
||||||
|
RegisterBarotrauma("Range`1[System.Int32]")
|
||||||
|
|
||||||
RegisterBarotrauma("Level+InterestingPosition")
|
RegisterBarotrauma("Level+InterestingPosition")
|
||||||
|
|
||||||
RegisterBarotrauma("RichString")
|
RegisterBarotrauma("RichString")
|
||||||
@@ -245,6 +248,8 @@ RegisterBarotrauma("Decal")
|
|||||||
RegisterBarotrauma("DecalPrefab")
|
RegisterBarotrauma("DecalPrefab")
|
||||||
RegisterBarotrauma("DecalManager")
|
RegisterBarotrauma("DecalManager")
|
||||||
|
|
||||||
|
RegisterBarotrauma("PriceInfo")
|
||||||
|
|
||||||
Register("Microsoft.Xna.Framework.Vector2")
|
Register("Microsoft.Xna.Framework.Vector2")
|
||||||
Register("Microsoft.Xna.Framework.Vector3")
|
Register("Microsoft.Xna.Framework.Vector3")
|
||||||
Register("Microsoft.Xna.Framework.Vector4")
|
Register("Microsoft.Xna.Framework.Vector4")
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
LuaSetup = {}
|
LuaSetup = {}
|
||||||
|
|
||||||
LuaSetup.Descriptors = {}
|
|
||||||
|
|
||||||
local path = table.pack(...)[1]
|
local path = table.pack(...)[1]
|
||||||
|
|
||||||
package.path = {path .. "/?.lua"}
|
package.path = {path .. "/?.lua"}
|
||||||
@@ -9,7 +7,7 @@ package.path = {path .. "/?.lua"}
|
|||||||
setmodulepaths(package.path)
|
setmodulepaths(package.path)
|
||||||
|
|
||||||
-- Setup Libraries
|
-- Setup Libraries
|
||||||
require("UserDataUtils")
|
require("LuaUserData")
|
||||||
|
|
||||||
require("DefaultRegister/RegisterShared")
|
require("DefaultRegister/RegisterShared")
|
||||||
|
|
||||||
@@ -37,7 +35,8 @@ AddTableToGlobal(require("CompatibilityLib"))
|
|||||||
|
|
||||||
require("DefaultHook")
|
require("DefaultHook")
|
||||||
|
|
||||||
Descriptors = LuaSetup.Descriptors
|
Descriptors = LuaSetup.LuaUserData.Descriptors
|
||||||
|
LuaUserData = LuaSetup.LuaUserData
|
||||||
|
|
||||||
LuaSetup = nil
|
LuaSetup = nil
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
local clrLuaUserData = LuaUserData
|
||||||
|
local luaUserData = {}
|
||||||
|
|
||||||
|
luaUserData.Descriptors = {}
|
||||||
|
|
||||||
|
LuaSetup.LuaUserData = luaUserData
|
||||||
|
|
||||||
|
luaUserData.UnregisterType = clrLuaUserData.UnregisterType
|
||||||
|
luaUserData.RegisterGenericType = clrLuaUserData.RegisterGenericType
|
||||||
|
luaUserData.UnregisterGenericType = clrLuaUserData.UnregisterGenericType
|
||||||
|
luaUserData.UnregisterGIsTargetTypeenericType = clrLuaUserData.IsTargetType
|
||||||
|
luaUserData.GetType = clrLuaUserData.GetType
|
||||||
|
luaUserData.CreateEnumTable = clrLuaUserData.CreateEnumTable
|
||||||
|
luaUserData.MakeFieldAccessible = clrLuaUserData.MakeFieldAccessible
|
||||||
|
luaUserData.MakeMethodAccessible = clrLuaUserData.MakeMethodAccessible
|
||||||
|
luaUserData.AddMethod = clrLuaUserData.AddMethod
|
||||||
|
luaUserData.AddField = clrLuaUserData.AddField
|
||||||
|
luaUserData.RemoveMember = clrLuaUserData.RemoveMember
|
||||||
|
luaUserData.CreateUserDataFromDescriptor = clrLuaUserData.CreateUserDataFromDescriptor
|
||||||
|
luaUserData.CreateUserDataFromType = clrLuaUserData.CreateUserDataFromType
|
||||||
|
|
||||||
|
luaUserData.RegisterType = function(typeName)
|
||||||
|
local descriptor = clrLuaUserData.RegisterType(typeName)
|
||||||
|
|
||||||
|
luaUserData.Descriptors[typeName] = descriptor
|
||||||
|
|
||||||
|
return descriptor
|
||||||
|
end
|
||||||
|
|
||||||
|
luaUserData.RegisterTypeBarotrauma = function(typeName)
|
||||||
|
return luaUserData.RegisterType("Barotrauma." .. typeName)
|
||||||
|
end
|
||||||
|
|
||||||
|
luaUserData.AddCallMetaTable = function (userdata)
|
||||||
|
debug.setmetatable(userdata, {
|
||||||
|
__call = function(obj, ...)
|
||||||
|
local success, result = pcall(userdata.__new, ...)
|
||||||
|
|
||||||
|
if not success then
|
||||||
|
error(result, 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
luaUserData.CreateStatic = function(typeName, addCallMethod)
|
||||||
|
local staticUserdata = clrLuaUserData.CreateStatic(typeName)
|
||||||
|
|
||||||
|
if addCallMethod then
|
||||||
|
luaUserData.AddCallMetaTable(staticUserdata)
|
||||||
|
end
|
||||||
|
|
||||||
|
return staticUserdata
|
||||||
|
end
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
LuaSetup.Register = function(typeName)
|
|
||||||
local descriptor = LuaUserData.RegisterType(typeName)
|
|
||||||
|
|
||||||
LuaSetup.Descriptors[typeName] = descriptor
|
|
||||||
|
|
||||||
return descriptor
|
|
||||||
end
|
|
||||||
|
|
||||||
LuaSetup.RegisterBarotrauma = function(typeName)
|
|
||||||
return LuaSetup.Register("Barotrauma." .. typeName)
|
|
||||||
end
|
|
||||||
|
|
||||||
LuaSetup.AddCallMetaTable = function (userdata)
|
|
||||||
debug.setmetatable(userdata, {
|
|
||||||
__call = function(obj, ...)
|
|
||||||
local success, result = pcall(userdata.__new, ...)
|
|
||||||
|
|
||||||
if not success then
|
|
||||||
error(result, 2)
|
|
||||||
end
|
|
||||||
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
LuaSetup.CreateStatic = function(typeName, addCallMethod)
|
|
||||||
local staticUserdata = LuaUserData.CreateStatic(typeName)
|
|
||||||
|
|
||||||
if addCallMethod then
|
|
||||||
LuaSetup.AddCallMetaTable(staticUserdata)
|
|
||||||
end
|
|
||||||
|
|
||||||
return staticUserdata
|
|
||||||
end
|
|
||||||
@@ -40,7 +40,7 @@ namespace Barotrauma
|
|||||||
return UserData.RegisterType(type);
|
return UserData.RegisterType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UnregisterType(string typeName)
|
public static void UnregisterType(string typeName, bool deleteHistory = false)
|
||||||
{
|
{
|
||||||
Type type = GetType(typeName);
|
Type type = GetType(typeName);
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ namespace Barotrauma
|
|||||||
throw new ScriptRuntimeException($"Tried to unregister a type that doesn't exist: {typeName}.");
|
throw new ScriptRuntimeException($"Tried to unregister a type that doesn't exist: {typeName}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
UserData.UnregisterType(type);
|
UserData.UnregisterType(type, deleteHistory);
|
||||||
}
|
}
|
||||||
public static IUserDataDescriptor RegisterGenericType(string typeName, params string[] typeNameArguements)
|
public static IUserDataDescriptor RegisterGenericType(string typeName, params string[] typeNameArguements)
|
||||||
{
|
{
|
||||||
@@ -192,6 +192,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
var descriptor = (StandardUserDataDescriptor)IUUD;
|
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||||
|
|
||||||
descriptor.RemoveMember(methodName);
|
descriptor.RemoveMember(methodName);
|
||||||
descriptor.AddMember(methodName, new ObjectCallbackMemberDescriptor(methodName, (object arg1, ScriptExecutionContext arg2, CallbackArguments arg3) =>
|
descriptor.AddMember(methodName, new ObjectCallbackMemberDescriptor(methodName, (object arg1, ScriptExecutionContext arg2, CallbackArguments arg3) =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user