Skip to content

Commit 35f0fd2

Browse files
LyrthUE4SS
andauthored
fix(Types.lua): General improvements to Types.lua and generated Lua type definition files (UE4SS-RE#821)
* fix(Types.lua): add local to some types as they're not actually globals * fix(Types.lua): missing containing class for some functions * fix(Types.lua): use builtin integer type for u/int types; small whitespace fixes * fix(SDKGenerator): LuaTypesGenerator: class and enum types should be local vars, add self param to methods defined with index notation * chore: Updated changelog --------- Co-authored-by: UE4SS <wildbrim@hotmail.com>
1 parent 78ed4aa commit 35f0fd2

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

UE4SS/src/SDKGenerator/Generator.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ namespace RC::UEGenerator
10921092
auto generate_enum_declaration(File::StringType& content_buffer, UEnum* uenum) -> void
10931093
{
10941094
auto enum_name = uenum->GetName();
1095-
content_buffer.append(fmt::format(STR("---@enum {}\n{} = {{\n"), enum_name, enum_name));
1095+
content_buffer.append(fmt::format(STR("---@enum {}\nlocal {} = {{\n"), enum_name, enum_name));
10961096
}
10971097
auto generate_enum_member(File::StringType& content_buffer, UEnum* uenum, const File::StringType& enum_value_name, const Unreal::FEnumNamePair& elem) -> void
10981098
{
@@ -1218,7 +1218,7 @@ namespace RC::UEGenerator
12181218
int32_t num_padding_elements,
12191219
XProperty* last_property_in_this_class) -> void
12201220
{
1221-
content_buffer.append(fmt::format(STR("{} = {{}}\n"), class_name));
1221+
content_buffer.append(fmt::format(STR("local {} = {{}}\n"), class_name));
12221222
}
12231223
auto generate_class_end(File::StringType& content_buffer, size_t class_size) -> void
12241224
{
@@ -1278,7 +1278,8 @@ namespace RC::UEGenerator
12781278
}
12791279
else
12801280
{
1281-
current_class_content.append(fmt::format(STR("{}[{}] = function("), class_name, quote_lua_symbol(function_name)));
1281+
// `function MyClass:MyMethod(p1, p2)` is syntactical sugar for `function MyClass.MyMethod(self, p1, p2)`
1282+
current_class_content.append(fmt::format(STR("{}[{}] = function(self, "), class_name, quote_lua_symbol(function_name)));
12821283
}
12831284

12841285
for (size_t i = 0; i < function_info.params.size(); ++i)

assets/Changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ function. ([UE4SS #800](https://github.com/UE4SS-RE/RE-UE4SS/pull/800))
242242
Fixed race condition when using RegisterCustomEvent or
243243
UnregisterCustomEvent. ([UE4SS #805](https://github.com/UE4SS-RE/RE-UE4SS/pull/805))
244244

245+
Fixed problems that caused issues for language servers. ([UE4SS #821](https://github.com/UE4SS-RE/RE-UE4SS/pull/821)
246+
245247
### C++ API
246248
Fixed a crash caused by a race condition enabled by C++ mods using `UE4SS_ENABLE_IMGUI` in their constructor ([UE4SS #481](https://github.com/UE4SS-RE/RE-UE4SS/pull/481))
247249

assets/Mods/shared/Types.lua

+36-29
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,18 @@ EInternalObjectFlags = {
266266
AllFlags = 0x7F800000,
267267
}
268268

269-
---@alias int8 number
270-
---@alias int16 number
271-
---@alias int32 number
272-
---@alias int64 number
273-
---@alias uint8 number
274-
---@alias uint16 number
275-
---@alias uint32 number
276-
---@alias uint64 number
269+
---@alias int8 integer
270+
---@alias int16 integer
271+
---@alias int32 integer
272+
---@alias int64 integer
273+
---@alias uint8 integer
274+
---@alias uint16 integer
275+
---@alias uint32 integer
276+
---@alias uint64 integer
277277
---@alias float number
278278
---@alias double number
279279

280+
280281
-- # Global Functions
281282

282283
---Creates an blank UObject whose IsValid function always returns false
@@ -602,6 +603,7 @@ function LoopAsync(DelayInMilliseconds, Callback) end
602603
---You also use `.__name` and `.__absolute_path` for files.
603604
function IterateGameDirectories() end
604605

606+
605607
-- # Classes
606608

607609
---Class for interacting with UE4SS metadata
@@ -696,8 +698,9 @@ function UnrealVersion:IsAbove(MajorVersion, MinorVersion) end
696698
---@return boolean
697699
function UnrealVersion.IsAbove(MajorVersion, MinorVersion) end
698700

701+
699702
---@class UFunction : UObject
700-
UFunction = {}
703+
local UFunction = {}
701704

702705
---Attempts to call the UFunction
703706
---@param ... UFunctionParams
@@ -714,7 +717,7 @@ function UFunction:SetFunctionFlags(Flags) end
714717

715718
---A TArray of characters
716719
---@class FString
717-
FString = {}
720+
local FString = {}
718721

719722
---Returns a string that Lua can understand
720723
---@return string
@@ -725,7 +728,7 @@ function FString:Clear() end
725728

726729

727730
---@class FieldClass : LocalObject
728-
FieldClass = {}
731+
local FieldClass = {}
729732

730733
---Returns the FName of this class by copy.
731734
---@return FName
@@ -751,15 +754,15 @@ FText = {}
751754
function FText:ToString() end
752755

753756
---@class RemoteObject
754-
RemoteObject = {}
757+
local RemoteObject = {}
755758

756759
---Returns whether this object is valid or not
757760
---@return boolean
758761
function RemoteObject:IsValid() end
759762

760763

761764
---@class Property : RemoteObject
762-
Property = {}
765+
local Property = {}
763766
---Returns the full name & path for this property.
764767
---@return string
765768
function Property:GetFullName() end
@@ -792,42 +795,47 @@ function Property:ImportText(Buffer, Data, PortFlags, OwnerObject) end
792795

793796

794797
---@class ObjectProperty : Property
795-
ObjectProperty = {}
798+
local ObjectProperty = {}
796799

797800
---Returns the class that this property holds.
798801
---@return UClass
799-
function GetPropertyClass() end
802+
function ObjectProperty:GetPropertyClass() end
800803

801804

802805
---@class BoolProperty : Property
806+
local BoolProperty = {}
803807

804808
---@return integer
805-
function GetByteMask() end
809+
function BoolProperty:GetByteMask() end
806810

807811
---@return integer
808-
function GetByteOffset() end
812+
function BoolProperty:GetByteOffset() end
809813

810814
---@return integer
811-
function GetFieldMask() end
815+
function BoolProperty:GetFieldMask() end
812816

813817
---@return integer
814-
function GetFieldSize() end
818+
function BoolProperty:GetFieldSize() end
815819

816820

817821
---@class StructProperty : Property
822+
local StructProperty = {}
823+
818824
---Returns the UScriptStruct that's mapped to this property.
819825
---@return UScriptStruct
820-
function GetStruct() end
826+
function StructProperty:GetStruct() end
821827

822828

823829
---@class ArrayProperty : Property
830+
local ArrayProperty = {}
831+
824832
---Returns the inner property of the array.
825833
---@return Property
826-
function GetInner() end
834+
function ArrayProperty:GetInner() end
827835

828836

829837
---@class UObjectReflection
830-
UObjectReflection = {}
838+
local UObjectReflection = {}
831839

832840
---Returns a property meta-data object
833841
---@param PropertyName string
@@ -836,7 +844,7 @@ function UObjectReflection:GetProperty(PropertyName) end
836844

837845

838846
---@class UObject : RemoteObject
839-
UObject = {}
847+
local UObject = {}
840848

841849
---Attempts to return either a member variable or a callable UFunction
842850
---Can return any type, you can use the `type()` function on the returned value to figure out what Lua class it's using (if non-trivial type)
@@ -938,7 +946,7 @@ function UObject:ProcessConsoleExec(Cmd, Reserved, Executor) end
938946
function UObject:type() end
939947

940948
---@class TArray<T> : { [integer]: T }
941-
TArray = {}
949+
local TArray = {}
942950

943951
---Return the address in memory where the TArray struct is located
944952
---@return integer
@@ -968,7 +976,7 @@ function TArray:ForEach(Callback) end
968976
---@class TSet<K> : { [K]: nil }
969977

970978
---@class TMap<K, V> : { [K]: V }
971-
TMap = {}
979+
local TMap = {}
972980

973981
---Find the specified key in the map
974982
---Throws an exception if the key is not found
@@ -1015,7 +1023,7 @@ function TMap:ForEach(callback) end
10151023
---Whether the Remote or Local variant is used depends on the requirements of the data but the usage is identical with either param types
10161024
---@generic T
10171025
---@class RemoteUnrealParam<T> : RemoteObject<T>
1018-
RemoteUnrealParam = {}
1026+
local RemoteUnrealParam = {}
10191027

10201028
---Returns the underlying value for this param
10211029
---@generic T
@@ -1040,8 +1048,7 @@ function RemoteUnrealParam:type() end
10401048

10411049

10421050
---@class UEnum
1043-
1044-
UEnum = {}
1051+
local UEnum = {}
10451052

10461053
--- Returns the `FName` that corresponds to the specified value.
10471054
---@param Value integer
@@ -1055,7 +1062,7 @@ function UEnum:ForEachName(Callback) end
10551062

10561063
--- Returns the `FName` and `Integer` value that coresponds the given `Index`.
10571064
---@param Index integer
1058-
function GetEnumNameByIndex(Index) end
1065+
function UEnum:GetEnumNameByIndex(Index) end
10591066

10601067
--- Inserts a `FName`/`Value` combination into a a `UEnum` at the given `Index`.
10611068
--- If `ShiftValues = true`, will shift all enum values greater than inserted value by one.

0 commit comments

Comments
 (0)