Minor refactor for LuaUserData.lua
This commit is contained in:
@@ -2,10 +2,6 @@
|
||||
|
||||
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")
|
||||
|
||||
LuaUserData.AddMethod(networking, "RequestGetHTTP", Networking.HttpGet)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local defaultLib = {}
|
||||
|
||||
local CreateStatic = LuaSetup.CreateStatic
|
||||
local CreateEnum = LuaUserData.CreateEnumTable
|
||||
local CreateStatic = LuaSetup.LuaUserData.CreateStatic
|
||||
local CreateEnum = LuaSetup.LuaUserData.CreateEnumTable
|
||||
|
||||
local localizedStrings = {
|
||||
"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 CreateStatic = LuaSetup.CreateStatic
|
||||
local CreateEnum = LuaUserData.CreateEnumTable
|
||||
local CreateStatic = LuaSetup.LuaUserData.CreateStatic
|
||||
local CreateEnum = LuaSetup.LuaUserData.CreateEnumTable
|
||||
|
||||
local localizedStrings = {
|
||||
"LocalizedString", "AddedPunctuationLString", "CapitalizeLString", "ConcatLString", "FallbackLString", "FormattedLString", "InputTypeLString", "JoinLString", "LowerLString", "RawLString", "ReplaceLString", "ServerMsgLString", "SplitLString", "TagLString", "TrimLString", "UpperLString", "StripRichTagsLString",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
local defaultLib = {}
|
||||
|
||||
local AddCallMetaTable = LuaSetup.AddCallMetaTable
|
||||
local CreateStatic = LuaSetup.CreateStatic
|
||||
local CreateEnum = LuaUserData.CreateEnumTable
|
||||
local AddCallMetaTable = LuaSetup.LuaUserData.AddCallMetaTable
|
||||
local CreateStatic = LuaSetup.LuaUserData.CreateStatic
|
||||
local CreateEnum = LuaSetup.LuaUserData.CreateEnumTable
|
||||
|
||||
require("DefaultLib/Utils/SteamApi")
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local Register = LuaSetup.Register
|
||||
local RegisterBarotrauma = LuaSetup.RegisterBarotrauma
|
||||
local Register = LuaSetup.LuaUserData.RegisterType
|
||||
local RegisterBarotrauma = LuaSetup.LuaUserData.RegisterTypeBarotrauma
|
||||
|
||||
local localizedStrings = {
|
||||
"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("GUIMessage")
|
||||
RegisterBarotrauma("GUIMessageBox")
|
||||
RegisterBarotrauma("GUIFont")
|
||||
RegisterBarotrauma("GUIFontPrefab")
|
||||
RegisterBarotrauma("GUIColorPicker")
|
||||
RegisterBarotrauma("GUIProgressBar")
|
||||
RegisterBarotrauma("GUICustomComponent")
|
||||
RegisterBarotrauma("GUIScissorComponent")
|
||||
RegisterBarotrauma("GUIComponentStyle")
|
||||
RegisterBarotrauma("GUIFontPrefab")
|
||||
RegisterBarotrauma("GUIFont")
|
||||
RegisterBarotrauma("GUISpritePrefab")
|
||||
RegisterBarotrauma("GUISprite")
|
||||
RegisterBarotrauma("GUISpriteSheetPrefab")
|
||||
RegisterBarotrauma("GUISpriteSheet")
|
||||
RegisterBarotrauma("GUICursorPrefab")
|
||||
RegisterBarotrauma("GUICursor")
|
||||
|
||||
RegisterBarotrauma("Inventory+SlotReference")
|
||||
@@ -1,5 +1,5 @@
|
||||
local Register = LuaSetup.Register
|
||||
local RegisterBarotrauma = LuaSetup.RegisterBarotrauma
|
||||
local Register = LuaSetup.LuaUserData.RegisterType
|
||||
local RegisterBarotrauma = LuaSetup.LuaUserData.RegisterTypeBarotrauma
|
||||
|
||||
|
||||
local localizedStrings = {
|
||||
@@ -10,6 +10,8 @@ for key, value in pairs(localizedStrings) do
|
||||
RegisterBarotrauma(value)
|
||||
end
|
||||
|
||||
RegisterBarotrauma("Character+TeamChangeEventData")
|
||||
|
||||
RegisterBarotrauma("Networking.GameServer")
|
||||
|
||||
RegisterBarotrauma("Networking.ServerPeer")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local Register = LuaSetup.Register
|
||||
local RegisterBarotrauma = LuaSetup.RegisterBarotrauma
|
||||
local Register = LuaSetup.LuaUserData.RegisterType
|
||||
local RegisterBarotrauma = LuaSetup.LuaUserData.RegisterTypeBarotrauma
|
||||
|
||||
Register("System.TimeSpan")
|
||||
Register("System.Exception")
|
||||
@@ -8,6 +8,9 @@ RegisterBarotrauma("LuaByte")
|
||||
RegisterBarotrauma("LuaUShort")
|
||||
RegisterBarotrauma("LuaFloat")
|
||||
|
||||
RegisterBarotrauma("Range`1[System.Single]")
|
||||
RegisterBarotrauma("Range`1[System.Int32]")
|
||||
|
||||
RegisterBarotrauma("Level+InterestingPosition")
|
||||
|
||||
RegisterBarotrauma("RichString")
|
||||
@@ -245,6 +248,8 @@ RegisterBarotrauma("Decal")
|
||||
RegisterBarotrauma("DecalPrefab")
|
||||
RegisterBarotrauma("DecalManager")
|
||||
|
||||
RegisterBarotrauma("PriceInfo")
|
||||
|
||||
Register("Microsoft.Xna.Framework.Vector2")
|
||||
Register("Microsoft.Xna.Framework.Vector3")
|
||||
Register("Microsoft.Xna.Framework.Vector4")
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
LuaSetup = {}
|
||||
|
||||
LuaSetup.Descriptors = {}
|
||||
|
||||
local path = table.pack(...)[1]
|
||||
|
||||
package.path = {path .. "/?.lua"}
|
||||
@@ -9,7 +7,7 @@ package.path = {path .. "/?.lua"}
|
||||
setmodulepaths(package.path)
|
||||
|
||||
-- Setup Libraries
|
||||
require("UserDataUtils")
|
||||
require("LuaUserData")
|
||||
|
||||
require("DefaultRegister/RegisterShared")
|
||||
|
||||
@@ -37,7 +35,8 @@ AddTableToGlobal(require("CompatibilityLib"))
|
||||
|
||||
require("DefaultHook")
|
||||
|
||||
Descriptors = LuaSetup.Descriptors
|
||||
Descriptors = LuaSetup.LuaUserData.Descriptors
|
||||
LuaUserData = LuaSetup.LuaUserData
|
||||
|
||||
LuaSetup = nil
|
||||
|
||||
|
||||
56
Barotrauma/BarotraumaShared/Lua/LuaUserData.lua
Normal file
56
Barotrauma/BarotraumaShared/Lua/LuaUserData.lua
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
public static void UnregisterType(string typeName)
|
||||
public static void UnregisterType(string typeName, bool deleteHistory = false)
|
||||
{
|
||||
Type type = GetType(typeName);
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Barotrauma
|
||||
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)
|
||||
{
|
||||
@@ -192,6 +192,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
var descriptor = (StandardUserDataDescriptor)IUUD;
|
||||
|
||||
descriptor.RemoveMember(methodName);
|
||||
descriptor.AddMember(methodName, new ObjectCallbackMemberDescriptor(methodName, (object arg1, ScriptExecutionContext arg2, CallbackArguments arg3) =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user