-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom.lua
42 lines (39 loc) · 2.1 KB
/
custom.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
---@generic K
---@param object K[]
---@param name string
---@return K
local function getObject(object, name)
for index, value in ipairs(object) do
if value.name == name then
return value
end
end
end
local LuaBootstrap = getObject(data.classes, "LuaBootstrap")
local on_event = getObject(LuaBootstrap.methods, "on_event")
on_event.custom = [[---Register a handler to run on the specified event(s). Each mod can only register once for every event, as any additional registration will overwrite the previous one. This holds true even if different filters are used for subsequent registrations.
---
---Register for the [on_tick](on_tick) event to print the current tick to console each tick.
---```lua
---script.on_event(defines.events.on_tick,
---function(event) game.print(event.tick) end)
---```
---\
---Register for the [on_built_entity](on_built_entity) event, limiting it to only be received when a `"fast-inserter"` is built.
---```lua
---script.on_event(defines.events.on_built_entity,
---function(event) game.print("Gotta go fast!") end,
---{{filter = "name", name = "fast-inserter"}})
---```
---@generic K
---@param _event defines.events|defines.events[]|string|K @The event(s) or custom-input to invoke the handler on.
---@param _f fun(event:K) @The handler for this event. Passing `nil` will unregister it.
---@param _filters? EventFilter[] @The filters for this event. Can only be used when registering for individual events.
function LuaBootstrap.on_event(_event, _f, _filters) end
]]
local LuaLazyLoadedValue = getObject(data.classes, "LuaLazyLoadedValue")
LuaLazyLoadedValue.custom = [[---A lazily loaded value. For performance reasons, we sometimes return a custom lazily-loaded value type instead of the native Lua value. This custom type lazily constructs the necessary value when [LuaLazyLoadedValue::get](LuaLazyLoadedValue::get) is called, therefore preventing its unnecessary construction in some cases.
---
---An instance of LuaLazyLoadedValue is only valid during the event it was created from and cannot be saved.
---@class LuaLazyLoadedValue<K>: {object_name:string; valid:boolean; get:fun():K; help:fun():string}
]]