Skip to content

Commit

Permalink
refactor: Rename function CreateBlankObject to CreateInvalidObject
Browse files Browse the repository at this point in the history
  • Loading branch information
igromanru committed Sep 30, 2024
1 parent 55479d5 commit 5f96538
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion UE4SS/src/Mod/LuaMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ namespace RC
{
lua.register_function("print", LuaLibrary::global_print);

lua.register_function("CreateBlankObject", [](const LuaMadeSimple::Lua& lua) -> int {
lua.register_function("CreateInvalidObject", [](const LuaMadeSimple::Lua& lua) -> int {
LuaType::auto_construct_object(lua, nullptr);
return 1;
});
Expand Down
2 changes: 1 addition & 1 deletion assets/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Added search filter: `IncludeClassNames`. ([UE4SS #472](https://github.com/UE4SS
### UHT Dumper

### Lua API
Added global function `CreateBlankObject`, which returns an invalid UObject. ([UE4SS #652](https://github.com/UE4SS-RE/RE-UE4SS/issues/652))
Added global function `CreateInvalidObject`, which returns an invalid UObject. ([UE4SS #652](https://github.com/UE4SS-RE/RE-UE4SS/issues/652))

### C++ API
Key binds created with `UE4SSProgram::register_keydown_event` end up being duplicated upon mod hot-reload.
Expand Down
2 changes: 1 addition & 1 deletion assets/Mods/shared/Types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ EInternalObjectFlags = {

---Creates an blank UObject whose IsValid function always returns false
---@return UObject
function CreateBlankObject() end
function CreateInvalidObject() end

---@param ObjectName string
---@return UObject
Expand Down
2 changes: 1 addition & 1 deletion docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
- [FWeakObjectPtr](./lua-api/classes/fweakobjectptr.md)
- [Global Functions]()
- [print](./lua-api/global-functions/print.md)
- [CreateBlankObject](./lua-api/global-functions/createblankobject.md)
- [CreateInvalidObject](./lua-api/global-functions/createinvalidobject.md)
- [FName](./lua-api/global-functions/fname.md)
- [FText](./lua-api/global-functions/ftext.md)
- [IterateGameDirectories](./lua-api/global-functions/iterategamedirectories.md)
Expand Down
3 changes: 2 additions & 1 deletion docs/lua-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ This is an overall list of API definitions available in UE4SS. For more readable
print(any... Message)
- Does not have the capability to format. Use 'string.format' if you require formatting.
CreateBlankObject() -> UObject
CreateInvalidObject() -> UObject
- Creates an object with an IsValid function that always returns false
StaticFindObject(string ObjectName) -> { UObject | AActor | nil }
StaticFindObject(UClass Class=nil, UObject InOuter=nil, string ObjectName, bool ExactClass=false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# CreateBlankObject
# CreateInvalidObject

The function `CreateBlankObject` always returns an object with an `IsValid` function that returns `flase`.
The function `CreateInvalidObject` always returns an object with an `IsValid` function that returns `flase`.

The sole purpose of the function is to ensure that the mod's Lua code adheres to UE4SS code conventions, where all functions return an invalid `UObject` instead of `nil`.

## Example
The example code below ensures that you never need to check if `EngineCache` is `nil`, and the same applies to the return value of `GetEngine()`.
```lua
local EngineCache = CreateBlankObject() ---@cast EngineCache UEngine
local EngineCache = CreateInvalidObject() ---@cast EngineCache UEngine
---Returns instance of UEngine
---@return UEngine
function GetEngine()
Expand Down

0 comments on commit 5f96538

Please sign in to comment.