3357 lines
151 KiB
HTML
3357 lines
151 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<link rel="stylesheet" href="style.css">
|
||
<title>flib documentation</title>
|
||
</head>
|
||
<body>
|
||
<h1>Factorio Library documentation</h1>
|
||
<p>This documentation is auto-generated by the Lua language server.
|
||
These docs are greatly unpolished and lack any quality of life features
|
||
whatsoever. This site will be replaced with a custom implementation in the
|
||
future.</p>
|
||
<nav>
|
||
<a href="https://github.com/factoriolib/flib">GitHub</a>
|
||
<a href="https://mods.factorio.com/mod/flib">Mod portal</a>
|
||
</nav>
|
||
<h1>Array</h1>
|
||
<hr />
|
||
<h1>DictLangRequest</h1>
|
||
<h2>player</h2>
|
||
<pre><code class="language-lua">LuaPlayer
|
||
</code></pre>
|
||
<p>A player in the game. Pay attention that a player may or may not have a character, which is the <a href="https://lua-api.factorio.com/latest/LuaEntity.html">LuaEntity</a> of the little guy running around the world doing things.</p>
|
||
<p><a href="https://lua-api.factorio.com/latest/LuaPlayer.html">View documentation</a></p>
|
||
<h2>tick</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>32 bit unsigned integer. Ranges from 0 to 4 294 967 295, or [0, 2^32-1]</p>
|
||
<hr />
|
||
<h1>DictTranslationRequest</h1>
|
||
<h2>dict</h2>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<h2>key</h2>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<h2>language</h2>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>DictWipData</h1>
|
||
<hr />
|
||
<h1>Dictionary</h1>
|
||
<p>Localised strings identified by an internal key. Keys must be unique and language-agnostic.</p>
|
||
<pre><code class="language-lua">table<string, boolean|string|number|LuaObject|boolean|string|number|LuaObject|boolean|string|number|LuaObject|nil[]...(+1)[]...(+1)>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>EventData.on_player_dictionaries_ready</h1>
|
||
<p>Called when a player's dictionaries are ready to be used. Handling this event is not required.</p>
|
||
<h2>player_index</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>32 bit unsigned integer. Ranges from 0 to 4 294 967 295, or [0, 2^32-1]</p>
|
||
<hr />
|
||
<h1>EventData.on_player_language_changed</h1>
|
||
<p>Called when a player's language changes. Handling this event is not required.</p>
|
||
<h2>language</h2>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<h2>player_index</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>32 bit unsigned integer. Ranges from 0 to 4 294 967 295, or [0, 2^32-1]</p>
|
||
<hr />
|
||
<h1>Gui</h1>
|
||
<hr />
|
||
<h1>GuiBase</h1>
|
||
<h2>build</h2>
|
||
<pre><code class="language-lua">function GuiBase.build(player: LuaPlayer)
|
||
</code></pre>
|
||
<p>Build the GUI for the given player.</p>
|
||
<h2>change_mode</h2>
|
||
<pre><code class="language-lua">function GuiBase.change_mode(self: Gui, e: EventData.on_gui_checked_state_changed)
|
||
</code></pre>
|
||
<h2>clear_completed</h2>
|
||
<pre><code class="language-lua">function GuiBase.clear_completed(self: Gui)
|
||
</code></pre>
|
||
<h2>hide</h2>
|
||
<pre><code class="language-lua">function GuiBase.hide(self: Gui)
|
||
</code></pre>
|
||
<h2>on_textfield_confirmed</h2>
|
||
<pre><code class="language-lua">function GuiBase.on_textfield_confirmed(self: Gui, e: EventData.on_gui_confirmed)
|
||
</code></pre>
|
||
<h2>on_textfield_text_changed</h2>
|
||
<pre><code class="language-lua">function GuiBase.on_textfield_text_changed(_: any, e: EventData.on_gui_confirmed)
|
||
</code></pre>
|
||
<h2>on_todo_toggled</h2>
|
||
<pre><code class="language-lua">function GuiBase.on_todo_toggled(self: Gui, e: EventData.on_gui_checked_state_changed)
|
||
</code></pre>
|
||
<h2>on_window_closed</h2>
|
||
<pre><code class="language-lua">function GuiBase.on_window_closed(self: Gui)
|
||
</code></pre>
|
||
<h2>show</h2>
|
||
<pre><code class="language-lua">function GuiBase.show(self: Gui)
|
||
</code></pre>
|
||
<h2>toggle_pinned</h2>
|
||
<pre><code class="language-lua">function GuiBase.toggle_pinned(self: Gui)
|
||
</code></pre>
|
||
<h2>toggle_visible</h2>
|
||
<pre><code class="language-lua">function GuiBase.toggle_visible(self: Gui)
|
||
</code></pre>
|
||
<h2>update_footer</h2>
|
||
<pre><code class="language-lua">function GuiBase.update_footer(self: Gui)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>GuiElemDef</h1>
|
||
<p>A GUI element definition. This extends <code>LuaGuiElement.add_param</code> with several new attributes.
|
||
Children may be defined in the array portion as an alternative to the <code>children</code> subtable.</p>
|
||
<pre><code class="language-lua">GuiElemDefClass|GuiElemDefClass|GuiElemDefClass|GuiElemDefClass[]|GuiElemDef|GuiElemDefClass[][]|GuiElemDef|GuiElemDefClass[][]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>GuiElemDefClass</h1>
|
||
<p>A GUI element definition. This extends <code>LuaGuiElement.add_param</code> with several new attributes.
|
||
Children may be defined in the array portion as an alternative to the <code>children</code> subtable.</p>
|
||
<h2>children</h2>
|
||
<pre><code class="language-lua">GuiElemDefClass|GuiElemDefClass|GuiElemDefClass[]|GuiElemDef|GuiElemDefClass[][]|GuiElemDef|GuiElemDefClass[][]?
|
||
</code></pre>
|
||
<p>Children to add to this element</p>
|
||
<h2>content</h2>
|
||
<pre><code class="language-lua">(GuiElemDefClass|GuiElemDefClass|GuiElemDefClass[]|GuiElemDef|GuiElemDefClass[][]|GuiElemDefClass|GuiElemDefClass|GuiElemDefClass[]|GuiElemDef|GuiElemDefClass[][]|GuiElemDef|GuiElemDefClass[][])?
|
||
</code></pre>
|
||
<p>To add a tab, specify <code>tab</code> and <code>content</code> and leave all other fields unset.</p>
|
||
<h2>drag_target</h2>
|
||
<pre><code class="language-lua">string?
|
||
</code></pre>
|
||
<p>Set the element's drag target to the element whose name matches this string. The drag target must be present in the <code>elems</code> table.</p>
|
||
<h2>elem_mods</h2>
|
||
<pre><code class="language-lua">LuaGuiElement?
|
||
</code></pre>
|
||
<p>Modifications to make to the element itself</p>
|
||
<h2>handler</h2>
|
||
<pre><code class="language-lua">(fun(e: EventData.on_gui_checked_state_changed|EventData.on_gui_click|EventData.on_gui_closed|EventData.on_gui_confirmed|EventData.on_gui_elem_changed...(+7))|table<defines.events,...(too long).....(+7))>)?
|
||
</code></pre>
|
||
<p>Handler(s) to assign to this element</p>
|
||
<h2>style_mods</h2>
|
||
<pre><code class="language-lua">LuaStyle?
|
||
</code></pre>
|
||
<p>Modifications to make to the element's style</p>
|
||
<h2>tab</h2>
|
||
<pre><code class="language-lua">(GuiElemDefClass|GuiElemDefClass|GuiElemDefClass[]|GuiElemDef|GuiElemDefClass[][]|GuiElemDefClass|GuiElemDefClass|GuiElemDefClass[]|GuiElemDef|GuiElemDefClass[][]|GuiElemDef|GuiElemDefClass[][])?
|
||
</code></pre>
|
||
<p>To add a tab, specify <code>tab</code> and <code>content</code> and leave all other fields unset.</p>
|
||
<hr />
|
||
<h1>GuiElemHandler</h1>
|
||
<p>A handler function to invoke when receiving GUI events for this element. Alternatively, separate handlers may be
|
||
specified for different events.</p>
|
||
<pre><code class="language-lua">fun(e: EventData.on_gui_checked_state_changed|EventData.on_gui_click|EventData.on_gui_closed|EventData.on_gui_confirmed|EventData.on_gui_elem_changed...(+7))|table<defines.events, ...(too long)...d...(+7))>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>GuiEventData</h1>
|
||
<p>Aggregate type of all possible GUI events.</p>
|
||
<pre><code class="language-lua">EventData.on_gui_checked_state_changed|EventData.on_gui_click|EventData.on_gui_closed|EventData.on_gui_confirmed|EventData.on_gui_elem_changed...(+7)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>IconSpecification</h1>
|
||
<h2>icon</h2>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<h2>icon_size</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>32 bit signed integer. Ranges from -2 147 483 648 to 2 147 483 647, or [-2^31, 2^31-1]</p>
|
||
<hr />
|
||
<h1>LuaUnit</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>MigrationsTable</h1>
|
||
<p>Migration code to run for specific mod version. A given function will run if the previous mod version is less
|
||
than the given version.</p>
|
||
<h1>Example</h1>
|
||
<pre><code class="language-lua">{
|
||
["1.0.1"] = function()
|
||
global.foo = nil
|
||
for _, player_table in pairs(global.players) do
|
||
player_table.bar = "Lorem ipsum"
|
||
end
|
||
end,
|
||
["1.0.7"] = function()
|
||
global.bar = {}
|
||
end
|
||
["1.1.0"] = function(arg)
|
||
global.foo = arg
|
||
end
|
||
}
|
||
</code></pre>
|
||
<p>If the mod is upgraded from 1.0.4 to 1.1.0, then the migrations for 1.0.7 and 1.1.0 will be run.</p>
|
||
<pre><code class="language-lua">table<string, fun(...any)>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Queue</h1>
|
||
<hr />
|
||
<h1>RawDictionary</h1>
|
||
<hr />
|
||
<h1>SpriteSpecification</h1>
|
||
<hr />
|
||
<h1>TaskIdent</h1>
|
||
<p>A unique identifier for a previously added task, used in <code>on-tick-n.remove</code>.</p>
|
||
<h2>index</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<p>The tasks' index in the tick's <code>Tasks</code> table.</p>
|
||
<h2>tick</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<p>The tick this task is scheduled for.</p>
|
||
<hr />
|
||
<h1>Tasks</h1>
|
||
<p>A table of tasks.</p>
|
||
<p>Each task can be anything that is not a function, as specified in <code>on-tick-n.add</code>.</p>
|
||
<p><strong>This is not an array, there may be gaps. Always use <code>pairs</code> to iterate this table.</strong></p>
|
||
<h1>Example</h1>
|
||
<pre><code class="language-lua">event.on_tick(function(e)
|
||
for _, task in pairs(on_tick_n.retrieve(e.tick) or {}) do
|
||
if task == "say_hi" then
|
||
game.print("Hello there!")
|
||
elseif task == "order_66" then
|
||
for _, player in pairs(game.players) do
|
||
player.die()
|
||
end
|
||
end
|
||
end
|
||
end)
|
||
</code></pre>
|
||
<pre><code class="language-lua">table<number, any>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_ceiled</h1>
|
||
<pre><code class="language-lua">function Test_ceiled()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_ceiled()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_clamp</h1>
|
||
<pre><code class="language-lua">function Test_clamp()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_clamp()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_degrees</h1>
|
||
<pre><code class="language-lua">function Test_degrees()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_degrees()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_floored</h1>
|
||
<pre><code class="language-lua">function Test_floored()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_floored()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_lerp</h1>
|
||
<pre><code class="language-lua">function Test_lerp()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_lerp()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_maximum</h1>
|
||
<pre><code class="language-lua">function Test_maximum()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_maximum()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_mean</h1>
|
||
<pre><code class="language-lua">function Test_mean()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_mean()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_midrange</h1>
|
||
<pre><code class="language-lua">function Test_midrange()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_midrange()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_minimum</h1>
|
||
<pre><code class="language-lua">function Test_minimum()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_minimum()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_radians</h1>
|
||
<pre><code class="language-lua">function Test_radians()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_radians()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_range</h1>
|
||
<pre><code class="language-lua">function Test_range()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_range()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_round</h1>
|
||
<pre><code class="language-lua">function Test_round()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_round()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_sign</h1>
|
||
<pre><code class="language-lua">function Test_sign()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_sign()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>Test_sum</h1>
|
||
<pre><code class="language-lua">function Test_sum()
|
||
</code></pre>
|
||
<pre><code class="language-lua">function Test_sum()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>TrainCompositionCounts</h1>
|
||
<h2>back_movers</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<p>The number of back-facing locomotives in the train.</p>
|
||
<h2>front_movers</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<p>The number of front-facing locomotives in the train.</p>
|
||
<h2>total</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<p>The total number of rolling stocks in the train.</p>
|
||
<h2>wagons</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<p>The number of wagons in the train.</p>
|
||
<hr />
|
||
<h1>TranslatedDictionary</h1>
|
||
<p>Translations are identified by their internal key. If the translation failed, then it will not be present. Locale
|
||
fallback groups can be used if every key needs a guaranteed translation.</p>
|
||
<pre><code class="language-lua">table<string, string>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>_FAKETORIO_globals</h1>
|
||
<pre><code class="language-lua">boolean
|
||
</code></pre>
|
||
<pre><code class="language-lua">boolean
|
||
</code></pre>
|
||
<hr />
|
||
<h1>_FAKETORIO_searcher</h1>
|
||
<pre><code class="language-lua">boolean
|
||
</code></pre>
|
||
<pre><code class="language-lua">boolean
|
||
</code></pre>
|
||
<hr />
|
||
<h1>_G</h1>
|
||
<p>A global variable (not a function) that holds the global environment (see <a href="http://www.lua.org/manual/5.2/manual.html#2.2">§2.2</a>). Lua itself does not use this variable; changing its value does not affect any environment, nor vice versa.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-_G">View documents</a></p>
|
||
<pre><code class="language-lua">_G
|
||
</code></pre>
|
||
<hr />
|
||
<h1>_VERSION</h1>
|
||
<p>A global variable (not a function) that holds a string containing the running Lua version.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-_VERSION">View documents</a></p>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>__object_name</h1>
|
||
<pre><code class="language-lua">object_name:
|
||
| "LuaAISettings"
|
||
| "LuaAccumulatorControlBehavior"
|
||
| "LuaAchievementPrototype"
|
||
| "LuaAmmoCategoryPrototype"
|
||
| "LuaArithmeticCombinatorControlBehavior"
|
||
| "LuaAutoplaceControlPrototype"
|
||
| "LuaBootstrap"
|
||
| "LuaBurner"
|
||
| "LuaBurnerPrototype"
|
||
| "LuaChunkIterator"
|
||
| "LuaCircuitNetwork"
|
||
| "LuaCommandProcessor"
|
||
| "LuaConstantCombinatorControlBehavior"
|
||
| "LuaContainerControlBehavior"
|
||
| "LuaCustomChartTag"
|
||
| "LuaCustomInputPrototype"
|
||
| "LuaCustomTable"
|
||
| "LuaDamagePrototype"
|
||
| "LuaDeciderCombinatorControlBehavior"
|
||
| "LuaDecorativePrototype"
|
||
| "LuaElectricEnergySourcePrototype"
|
||
| "LuaEntity"
|
||
| "LuaEntityPrototype"
|
||
| "LuaEquipment"
|
||
| "LuaEquipmentCategoryPrototype"
|
||
| "LuaEquipmentGrid"
|
||
| "LuaEquipmentGridPrototype"
|
||
| "LuaEquipmentPrototype"
|
||
| "LuaFlowStatistics"
|
||
| "LuaFluidBox"
|
||
| "LuaFluidBoxPrototype"
|
||
| "LuaFluidEnergySourcePrototype"
|
||
| "LuaFluidPrototype"
|
||
| "LuaFontPrototype"
|
||
| "LuaForce"
|
||
| "LuaFuelCategoryPrototype"
|
||
| "LuaGameScript"
|
||
| "LuaGroup"
|
||
| "LuaGui"
|
||
| "LuaGuiElement"
|
||
| "LuaHeatBufferPrototype"
|
||
| "LuaHeatEnergySourcePrototype"
|
||
| "LuaInserterControlBehavior"
|
||
| "LuaInventory"
|
||
| "LuaItemPrototype"
|
||
| "LuaItemStack"
|
||
| "LuaLampControlBehavior"
|
||
| "LuaLazyLoadedValue"
|
||
| "LuaLogisticCell"
|
||
| "LuaLogisticContainerControlBehavior"
|
||
| "LuaLogisticNetwork"
|
||
| "LuaLogisticPoint"
|
||
| "LuaMiningDrillControlBehavior"
|
||
| "LuaModSettingPrototype"
|
||
| "LuaModuleCategoryPrototype"
|
||
| "LuaNamedNoiseExpression"
|
||
| "LuaNoiseLayerPrototype"
|
||
| "LuaParticlePrototype"
|
||
| "LuaPermissionGroup"
|
||
| "LuaPermissionGroups"
|
||
| "LuaPlayer"
|
||
| "LuaProfiler"
|
||
| "LuaProgrammableSpeakerControlBehavior"
|
||
| "LuaRCON"
|
||
| "LuaRailChainSignalControlBehavior"
|
||
| "LuaRailPath"
|
||
| "LuaRailSignalControlBehavior"
|
||
| "LuaRandomGenerator"
|
||
| "LuaRecipe"
|
||
| "LuaRecipeCategoryPrototype"
|
||
| "LuaRecipePrototype"
|
||
| "LuaRemote"
|
||
| "LuaRendering"
|
||
| "LuaResourceCategoryPrototype"
|
||
| "LuaRoboportControlBehavior"
|
||
| "LuaSettings"
|
||
| "LuaShortcutPrototype"
|
||
| "LuaStorageTankControlBehavior"
|
||
| "LuaStyle"
|
||
| "LuaSurface"
|
||
| "LuaTechnology"
|
||
| "LuaTechnologyPrototype"
|
||
| "LuaTile"
|
||
| "LuaTilePrototype"
|
||
| "LuaTrain"
|
||
| "LuaTrainStopControlBehavior"
|
||
| "LuaTransportBeltControlBehavior"
|
||
| "LuaTransportLine"
|
||
| "LuaTrivialSmokePrototype"
|
||
| "LuaUnitGroup"
|
||
| "LuaVirtualSignalPrototype"
|
||
| "LuaVoidEnergySourcePrototype"
|
||
| "LuaWallControlBehavior"
|
||
</code></pre>
|
||
<pre><code class="language-lua">function __object_name(object: LuaObject)
|
||
-> object_name: "LuaAISettings"|"LuaAccumulatorControlBehavior"|"LuaAchievementPrototype"|"LuaAmmoCategoryPrototype"|"LuaArithmeticCombinatorControlBehavior"...(+88)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>arg</h1>
|
||
<p>Command-line arguments of Lua Standalone.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-arg">View documents</a></p>
|
||
<pre><code class="language-lua">string[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>assert</h1>
|
||
<p>Raises an error if the value of its argument v is false (i.e., <code>nil</code> or <code>false</code>); otherwise, returns all its arguments. In case of error, <code>message</code> is the error object; when absent, it defaults to <code>"assertion failed!"</code></p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-assert">View documents</a></p>
|
||
<pre><code class="language-lua">function assert(v?: <T>, message?: any, ...any)
|
||
-> <T>
|
||
2. ...any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32</h1>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32">View documents</a></p>
|
||
<pre><code class="language-lua">bit32lib
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.arshift</h1>
|
||
<p>Returns the number <code>x</code> shifted <code>disp</code> bits to the right. Negative displacements shift to the left.</p>
|
||
<p>This shift operation is what is called arithmetic shift. Vacant bits on the left are filled with copies of the higher bit of <code>x</code>; vacant bits on the right are filled with zeros.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.arshift">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.arshift(x: integer, disp: integer)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.band</h1>
|
||
<p>Returns the bitwise <em>and</em> of its operands.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.band">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.band(...any)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.bnot</h1>
|
||
<p>Returns the bitwise negation of <code>x</code>.</p>
|
||
<pre><code class="language-lua">assert(bit32.bnot(x) ==
|
||
(-1 - x) % 2^32)
|
||
</code></pre>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.bnot">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.bnot(x: integer)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.bor</h1>
|
||
<p>Returns the bitwise <em>or</em> of its operands.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.bor">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.bor(...any)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.btest</h1>
|
||
<p>Returns a boolean signaling whether the bitwise <em>and</em> of its operands is different from zero.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.btest">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.btest(...any)
|
||
-> boolean
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.bxor</h1>
|
||
<p>Returns the bitwise <em>exclusive or</em> of its operands.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.bxor">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.bxor(...any)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.extract</h1>
|
||
<p>Returns the unsigned number formed by the bits <code>field</code> to <code>field + width - 1</code> from <code>n</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.extract">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.extract(n: integer, field: integer, width?: integer)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.lrotate</h1>
|
||
<p>Returns the number <code>x</code> rotated <code>disp</code> bits to the left. Negative displacements rotate to the right.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.lrotate">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.lrotate(x: integer, distp: integer)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.lshift</h1>
|
||
<p>Returns the number <code>x</code> shifted <code>disp</code> bits to the left. Negative displacements shift to the right. In any direction, vacant bits are filled with zeros.</p>
|
||
<pre><code class="language-lua">assert(bit32.lshift(b, disp) ==
|
||
(b * 2^disp) % 2^32)
|
||
</code></pre>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.lshift">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.lshift(x: integer, distp: integer)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.replace</h1>
|
||
<p>Returns a copy of <code>n</code> with the bits <code>field</code> to <code>field + width - 1</code> replaced by the value <code>v</code> .</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.replace">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.replace(n: integer, v: integer, field: integer, width?: integer)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.rrotate</h1>
|
||
<p>Returns the number <code>x</code> rotated <code>disp</code> bits to the right. Negative displacements rotate to the left.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.rrotate">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.rrotate(x: integer, distp: integer)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>bit32.rshift</h1>
|
||
<p>Returns the number <code>x</code> shifted <code>disp</code> bits to the right. Negative displacements shift to the left. In any direction, vacant bits are filled with zeros.</p>
|
||
<pre><code class="language-lua">assert(bit32.rshift(b, disp) ==
|
||
math.floor(b % 2^32 / 2^disp))
|
||
</code></pre>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-bit32.rshift">View documents</a></p>
|
||
<pre><code class="language-lua">function bit32.rshift(x: integer, distp: integer)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>collectgarbage</h1>
|
||
<p>This function is a generic interface to the garbage collector. It performs different functions according to its first argument, <code>opt</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-collectgarbage">View documents</a></p>
|
||
<pre><code class="language-lua">opt:
|
||
-> "collect" -- Performs a full garbage-collection cycle.
|
||
| "stop" -- Stops automatic execution.
|
||
| "restart" -- Restarts automatic execution.
|
||
| "count" -- Returns the total memory in Kbytes.
|
||
| "step" -- Performs a garbage-collection step.
|
||
| "isrunning" -- Returns whether the collector is running.
|
||
| "setpause" -- Set `pause`.
|
||
| "setstepmul" -- Set `step multiplier`.
|
||
</code></pre>
|
||
<pre><code class="language-lua">function collectgarbage(opt?: "collect"|"count"|"isrunning"|"restart"|"setpause"...(+3), arg?: integer)
|
||
-> any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>commands</h1>
|
||
<p><strong>Global Description:</strong><br />
|
||
Allows registration of custom commands for the in-game console.</p>
|
||
<p><strong>Class Description:</strong><br />
|
||
Allows for the registration of custom console commands through the global object named <code>commands</code>. Similarly to <a href="https://lua-api.factorio.com/latest/LuaBootstrap.html#LuaBootstrap.on_event">event subscriptions</a>, these don't persist through a save-and-load cycle.</p>
|
||
<p><a href="https://lua-api.factorio.com/latest/LuaCommandProcessor.html">View documentation</a></p>
|
||
<pre><code class="language-lua">LuaCommandProcessor
|
||
</code></pre>
|
||
<hr />
|
||
<h1>data</h1>
|
||
<pre><code class="language-lua">data
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug</h1>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">factorio.debuglib
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.debug</h1>
|
||
<p>Enters an interactive mode with the user, running each string that the user enters.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.debug%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.debug()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.gethook</h1>
|
||
<p>Returns the current hook settings of the thread.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.gethook%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.gethook()
|
||
-> hook: function
|
||
2. mask: string
|
||
3. count: integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.getinfo</h1>
|
||
<p>Returns a table with information about a function.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.getinfo%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">what:
|
||
+> "n" -- `name` and `namewhat`
|
||
+> "S" -- `source`, `short_src`, `linedefined`, `lastlinedefined`, and `what`
|
||
+> "l" -- `currentline`
|
||
+> "t" -- `istailcall`
|
||
+> "u" -- `nups`, `nparams`, and `isvararg`
|
||
+> "f" -- `func`
|
||
+> "L" -- `activelines`
|
||
+> "p" -- `currentpc`
|
||
</code></pre>
|
||
<pre><code class="language-lua">function debug.getinfo(f: integer|fun(...any):...unknown, what?: string|"L"|"S"|"f"|"l"...(+4))
|
||
-> debuginfo
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.getlocal</h1>
|
||
<p>Returns the name and the value of the local variable with index <code>local</code> of the function at level <code>f</code> of the stack.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.getlocal%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.getlocal(f: integer|fun(...any):...unknown, index: integer)
|
||
-> name: string
|
||
2. value: any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.getmetatable</h1>
|
||
<p>Returns the metatable of the given value.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.getmetatable%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.getmetatable(object: any)
|
||
-> metatable: table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.getregistry</h1>
|
||
<p>Returns the registry table.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.getregistry%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.getregistry()
|
||
-> table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.getupvalue</h1>
|
||
<p>Returns the name and the value of the upvalue with index <code>up</code> of the function.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.getupvalue%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.getupvalue(f: fun(...any):...unknown, up: integer)
|
||
-> name: string
|
||
2. value: any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.getuservalue</h1>
|
||
<p>Returns the Lua value associated to u.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.getuservalue%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.getuservalue(u: userdata)
|
||
-> any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.setcstacklimit</h1>
|
||
<h3><strong>Deprecated in <code>Lua 5.4.2</code></strong></h3>
|
||
<p>Sets a new limit for the C stack. This limit controls how deeply nested calls can go in Lua, with the intent of avoiding a stack overflow.</p>
|
||
<p>In case of success, this function returns the old limit. In case of error, it returns <code>false</code>.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.setcstacklimit%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.setcstacklimit(limit: integer)
|
||
-> boolean|integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.sethook</h1>
|
||
<p>Sets the given function as a hook.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.sethook%22%5D">View documents</a></p>
|
||
<hr />
|
||
<pre><code class="language-lua">mask:
|
||
+> "c" -- Calls hook when Lua calls a function.
|
||
+> "r" -- Calls hook when Lua returns from a function.
|
||
+> "l" -- Calls hook when Lua enters a new line of code.
|
||
</code></pre>
|
||
<pre><code class="language-lua">function debug.sethook(hook: fun(...any):...unknown, mask: string|"c"|"l"|"r", count?: integer)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.setlocal</h1>
|
||
<p>Assigns the <code>value</code> to the local variable with index <code>local</code> of the function at <code>level</code> of the stack.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.setlocal%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.setlocal(level: integer, index: integer, value: any)
|
||
-> name: string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.setmetatable</h1>
|
||
<p>Sets the metatable for the given value to the given table (which can be <code>nil</code>).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.setmetatable%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.setmetatable(value: <T>, meta?: table)
|
||
-> value: <T>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.setupvalue</h1>
|
||
<p>Assigns the <code>value</code> to the upvalue with index <code>up</code> of the function.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.setupvalue%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.setupvalue(f: fun(...any):...unknown, up: integer, value: any)
|
||
-> name: string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.setuservalue</h1>
|
||
<p>Sets the given value as the Lua value associated to the given udata.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.setuservalue%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.setuservalue(udata: userdata, value: any)
|
||
-> udata: userdata
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.traceback</h1>
|
||
<p>Returns a string with a traceback of the call stack. The optional message string is appended at the beginning of the traceback.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.traceback%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.traceback(thread: thread, message?: any, level?: integer)
|
||
-> message: string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.upvalueid</h1>
|
||
<p>Returns a unique identifier (as a light userdata) for the upvalue numbered <code>n</code> from the given function.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.upvalueid%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.upvalueid(f: fun(...any):...unknown, n: integer)
|
||
-> id: lightuserdata
|
||
</code></pre>
|
||
<hr />
|
||
<h1>debug.upvaluejoin</h1>
|
||
<p>Make the <code>n1</code>-th upvalue of the Lua closure <code>f1</code> refer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-debug.upvaluejoin%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function debug.upvaluejoin(f1: fun(...any):...unknown, n1: integer, f2: fun(...any):...unknown, n2: integer)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines</h1>
|
||
<p><a href="https://lua-api.factorio.com/latest/defines.html">View Documentation</a></p>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">defines
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.alert_type</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.behavior_result</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.build_check_type</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.chain_signal_state</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.chunk_generated_status</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.circuit_condition_index</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.circuit_connector_id</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.command</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.compound_command</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior</h1>
|
||
<p><a href="https://lua-api.factorio.com/latest/defines.html#defines.control_behavior">View Documentation</a></p>
|
||
<pre><code class="language-lua">defines.control_behavior
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.inserter</h1>
|
||
<p><a href="https://lua-api.factorio.com/latest/defines.html#defines.control_behavior.inserter">View Documentation</a></p>
|
||
<pre><code class="language-lua">defines.control_behavior.inserter
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.inserter.circuit_mode_of_operation</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.inserter.hand_read_mode</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.lamp</h1>
|
||
<p><a href="https://lua-api.factorio.com/latest/defines.html#defines.control_behavior.lamp">View Documentation</a></p>
|
||
<pre><code class="language-lua">defines.control_behavior.lamp
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.lamp.circuit_mode_of_operation</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.logistic_container</h1>
|
||
<p><a href="https://lua-api.factorio.com/latest/defines.html#defines.control_behavior.logistic_container">View Documentation</a></p>
|
||
<pre><code class="language-lua">defines.control_behavior.logistic_container
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.logistic_container.circuit_mode_of_operation</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.mining_drill</h1>
|
||
<p><a href="https://lua-api.factorio.com/latest/defines.html#defines.control_behavior.mining_drill">View Documentation</a></p>
|
||
<pre><code class="language-lua">defines.control_behavior.mining_drill
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.mining_drill.resource_read_mode</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.transport_belt</h1>
|
||
<p><a href="https://lua-api.factorio.com/latest/defines.html#defines.control_behavior.transport_belt">View Documentation</a></p>
|
||
<pre><code class="language-lua">defines.control_behavior.transport_belt
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.transport_belt.content_read_mode</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.control_behavior.type</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.controllers</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.deconstruction_item</h1>
|
||
<p><a href="https://lua-api.factorio.com/latest/defines.html#defines.deconstruction_item">View Documentation</a></p>
|
||
<pre><code class="language-lua">defines.deconstruction_item
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.deconstruction_item.entity_filter_mode</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.deconstruction_item.tile_filter_mode</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.deconstruction_item.tile_selection_mode</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.difficulty</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.difficulty_settings</h1>
|
||
<p><a href="https://lua-api.factorio.com/latest/defines.html#defines.difficulty_settings">View Documentation</a></p>
|
||
<pre><code class="language-lua">defines.difficulty_settings
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.difficulty_settings.recipe_difficulty</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.difficulty_settings.technology_difficulty</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.direction</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.disconnect_reason</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.distraction</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.entity_status</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.events</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.flow_precision_index</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.game_controller_interaction</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.group_state</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.gui_type</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.input_action</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.input_method</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.inventory</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.logistic_member_index</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.logistic_mode</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.mouse_button_type</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.prototypes</h1>
|
||
<p>A dictionary mapping all top-level prototypes by name to a list of their associated subtypes. This list is organized as a lookup table, meaning it maps the sub-prototype names to <code>0</code>. As an example, <code>defines.prototypes['entity']</code> looks like this: <code>{furnace=0, inserter=0, container=0, ...}</code>.</p>
|
||
<p><a href="https://lua-api.factorio.com/latest/defines.html#defines.prototypes">View Documentation</a></p>
|
||
<pre><code class="language-lua">defines.prototypes|{ [string]: { [string]: 0 } }
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.rail_connection_direction</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.rail_direction</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.relative_gui_position</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.relative_gui_type</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.render_mode</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.rich_text_setting</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.riding</h1>
|
||
<p><a href="https://lua-api.factorio.com/latest/defines.html#defines.riding">View Documentation</a></p>
|
||
<pre><code class="language-lua">defines.riding
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.riding.acceleration</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.riding.direction</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.rocket_silo_status</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.shooting</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.signal_state</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.train_state</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.transport_line</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.wire_connection_id</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>defines.wire_type</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>dofile</h1>
|
||
<p>Opens the named file and executes its content as a Lua chunk. When called without arguments, <code>dofile</code> executes the content of the standard input (<code>stdin</code>). Returns all values returned by the chunk. In case of errors, <code>dofile</code> propagates the error to its caller. (That is, <code>dofile</code> does not run in protected mode.)</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-dofile">View documents</a></p>
|
||
<pre><code class="language-lua">function dofile(filename?: string)
|
||
-> ...any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>error</h1>
|
||
<p>Terminates the last protected function called and returns message as the error object.</p>
|
||
<p>Usually, <code>error</code> adds some information about the error position at the beginning of the message, if the message is a string.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-error">View documents</a></p>
|
||
<pre><code class="language-lua">function error(message: any, level?: integer)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>flib_bounding_box</h1>
|
||
<p>Utilities for manipulating bounding boxes. All functions support both the shorthand and explicit syntaxes for boxes
|
||
and positions, and will preserve the syntax that was passed in. Boxes are considered immutable; all functions will
|
||
return new boxes.</p>
|
||
<pre><code class="language-lua">local flib_bounding_box = require("__flib__/bounding-box")
|
||
</code></pre>
|
||
<h2>ceil</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.ceil(box: BoundingBox.0|BoundingBox.1)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Return a new box expanded to the nearest tile edges.</p>
|
||
<h2>center</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.center(box: BoundingBox.0|BoundingBox.1)
|
||
-> MapPosition.0|MapPosition.1
|
||
</code></pre>
|
||
<p>Calculate the centerpoint of the box.</p>
|
||
<h2>contains_box</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.contains_box(box1: BoundingBox.0|BoundingBox.1, box2: BoundingBox.0|BoundingBox.1)
|
||
-> boolean
|
||
</code></pre>
|
||
<p>Check if the first box contains the second box.</p>
|
||
<h2>contains_position</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.contains_position(box: BoundingBox.0|BoundingBox.1, pos: MapPosition.0|MapPosition.1)
|
||
-> boolean
|
||
</code></pre>
|
||
<p>Check if the given box contains the given position.</p>
|
||
<h2>ensure_explicit</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.ensure_explicit(box: BoundingBox.0|BoundingBox.1)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Return the box in explicit form.</p>
|
||
<h2>ensure_short</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.ensure_short(box: BoundingBox.0|BoundingBox.1)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Return the box in shorthand form.</p>
|
||
<h2>expand_to_contain_box</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.expand_to_contain_box(box1: BoundingBox.0|BoundingBox.1, box2: BoundingBox.0|BoundingBox.1)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Return a new box with initial dimensions box1, expanded to contain box2.</p>
|
||
<h2>expand_to_contain_position</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.expand_to_contain_position(box: BoundingBox.0|BoundingBox.1, pos: MapPosition.0|MapPosition.1)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Return a new box expanded to contain the given position.</p>
|
||
<h2>floor</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.floor(box: BoundingBox.0|BoundingBox.1)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Return a new box shrunk to the nearest tile edges.</p>
|
||
<h2>from_dimensions</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.from_dimensions(center: MapPosition.0|MapPosition.1, width: number, height: number)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Create a new box from a centerpoint and dimensions.</p>
|
||
<h2>from_position</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.from_position(pos: MapPosition.0|MapPosition.1, snap?: boolean)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Create a 1x1 box from the given position, optionally snapped to the containing tile edges.</p>
|
||
<h2>height</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.height(box: BoundingBox.0|BoundingBox.1)
|
||
-> number
|
||
</code></pre>
|
||
<p>Calculate the height of the box.</p>
|
||
<h2>intersects_box</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.intersects_box(box1: BoundingBox.0|BoundingBox.1, box2: BoundingBox.0|BoundingBox.1)
|
||
-> boolean
|
||
</code></pre>
|
||
<p>Check if the first box intersects (overlaps) the second box.</p>
|
||
<h2>move</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.move(box: BoundingBox.0|BoundingBox.1, delta: MapPosition.0|MapPosition.1)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Return a new box with the same dimensions, moved by the given delta.</p>
|
||
<h2>recenter_on</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.recenter_on(box: BoundingBox.0|BoundingBox.1, pos: MapPosition.0|MapPosition.1)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Return a new box with the same dimensions centered on the given position.</p>
|
||
<h2>resize</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.resize(box: BoundingBox.0|BoundingBox.1, delta: number)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Return a new box grown or shrunk by the given delta. A positive delta will grow the box, a negative delta will
|
||
shrink it.</p>
|
||
<h2>rotate</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.rotate(box: BoundingBox.0|BoundingBox.1)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Return a new box rotated 90 degrees about its center.</p>
|
||
<h2>square</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.square(box: BoundingBox.0|BoundingBox.1)
|
||
-> BoundingBox.0|BoundingBox.1
|
||
</code></pre>
|
||
<p>Return a new box expanded to create a square.</p>
|
||
<h2>width</h2>
|
||
<pre><code class="language-lua">function flib_bounding_box.width(box: BoundingBox.0|BoundingBox.1)
|
||
-> number
|
||
</code></pre>
|
||
<p>Calculate the width of the box.</p>
|
||
<hr />
|
||
<h1>flib_data_util</h1>
|
||
<p>Utilities for data stage prototype manipulation.</p>
|
||
<pre><code class="language-lua">local flib_data_util = require("__flib__/data-util")
|
||
</code></pre>
|
||
<h2>black_image</h2>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<p>A black image, for use with tool backgrounds. This image is 1x1.</p>
|
||
<h2>build_sprite</h2>
|
||
<pre><code class="language-lua">function flib_data_util.build_sprite(name?: string, position?: MapPosition.0|MapPosition.1, filename?: string, size?: Vector.0|Vector.1, mipmap_count?: number, mods?: table)
|
||
-> SpriteSpecification
|
||
</code></pre>
|
||
<p>Build a sprite from constituent parts.</p>
|
||
<h2>copy_prototype</h2>
|
||
<pre><code class="language-lua">function flib_data_util.copy_prototype(prototype: table, new_name: string, remove_icon?: boolean)
|
||
-> table
|
||
</code></pre>
|
||
<p>Copy a prototype, assigning a new name and minable properties.</p>
|
||
<p>@<em>param</em> <code>new_name</code> — string</p>
|
||
<h2>create_icons</h2>
|
||
<pre><code class="language-lua">function flib_data_util.create_icons(prototype: table, new_layers?: IconSpecification[])
|
||
-> IconSpecification[]|nil
|
||
</code></pre>
|
||
<p>Copy prototype.icon/icons to a new fully defined icons array, optionally adding new icon layers.</p>
|
||
<p>Returns <code>nil</code> if the prototype's icons are incorrectly or incompletely defined.</p>
|
||
<h2>dark_red_button_tileset</h2>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<p>A dark red button tileset. Used for the <code>flib_tool_button_dark_red</code> style.</p>
|
||
<h2>empty_image</h2>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<p>An empty image. This image is 8x8 to facilitate usage with GUI styles.</p>
|
||
<h2>get_energy_value</h2>
|
||
<pre><code class="language-lua">function flib_data_util.get_energy_value(energy_string: string)
|
||
-> number?
|
||
2. string?
|
||
</code></pre>
|
||
<p>Convert an energy string to base unit value + suffix.</p>
|
||
<p>Returns <code>nil</code> if <code>energy_string</code> is incorrectly formatted.</p>
|
||
<h2>planner_base_image</h2>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<p>A desaturated planner image. Tint this sprite to easily add your own planners.</p>
|
||
<hr />
|
||
<h1>flib_dictionary</h1>
|
||
<p>Utilities for creating dictionaries of localised string translations.</p>
|
||
<pre><code class="language-lua">local flib_dictionary = require("__flib__/dictionary-lite")
|
||
</code></pre>
|
||
<h2>add</h2>
|
||
<pre><code class="language-lua">function flib_dictionary.add(dict_name: string, key: string, localised: boolean|string|number|LuaObject|boolean|string|number|LuaObject|boolean|string|number|LuaObject|nil[]...(+1)[]...(+1))
|
||
</code></pre>
|
||
<p>Add the given string to the dictionary.</p>
|
||
<h2>events</h2>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<p>For use with <code>__core__/lualib/event_handler</code>. Pass <code>flib_dictionary</code> into <code>handler.add_lib</code> to
|
||
handle all relevant events automatically.</p>
|
||
<h2>get</h2>
|
||
<pre><code class="language-lua">function flib_dictionary.get(player_index: integer, dict_name: string)
|
||
-> table<string, string>?
|
||
</code></pre>
|
||
<p>Get the specified dictionary for the player. Will return <code>nil</code> if the dictionary has not finished translating.</p>
|
||
<h2>get_all</h2>
|
||
<pre><code class="language-lua">function flib_dictionary.get_all(player_index: integer)
|
||
-> table<string, table<string, string>>?
|
||
</code></pre>
|
||
<p>Get all dictionaries for the player. Will return <code>nil</code> if the player's language has not finished translating.</p>
|
||
<h2>handle_events</h2>
|
||
<pre><code class="language-lua">function flib_dictionary.handle_events()
|
||
</code></pre>
|
||
<p>Handle all non-bootstrap events with default event handlers. Will not overwrite any existing handlers. If you have
|
||
custom handlers for on_tick, on_string_translated, or on_player_joined_game, ensure that you call the corresponding
|
||
module lifecycle handler..</p>
|
||
<h2>new</h2>
|
||
<pre><code class="language-lua">function flib_dictionary.new(name: string, initial_strings?: table<string, boolean|string|number|LuaObject|boolean|string|number|LuaObject|boolean|string|number|LuaObject|nil[]...(+1)[]...(+1)>)
|
||
</code></pre>
|
||
<p>Create a new dictionary. The name must be unique.</p>
|
||
<h2>on_configuration_changed</h2>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<h2>on_init</h2>
|
||
<pre><code class="language-lua">function flib_dictionary.on_init()
|
||
</code></pre>
|
||
<h2>on_player_dictionaries_ready</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>32 bit unsigned integer. Ranges from 0 to 4 294 967 295, or [0, 2^32-1]</p>
|
||
<h2>on_player_joined_game</h2>
|
||
<pre><code class="language-lua">function flib_dictionary.on_player_joined_game(e: EventData.on_player_joined_game)
|
||
</code></pre>
|
||
<h2>on_player_language_changed</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>32 bit unsigned integer. Ranges from 0 to 4 294 967 295, or [0, 2^32-1]</p>
|
||
<h2>on_string_translated</h2>
|
||
<pre><code class="language-lua">function flib_dictionary.on_string_translated(e: EventData.on_string_translated)
|
||
</code></pre>
|
||
<h2>on_tick</h2>
|
||
<pre><code class="language-lua">function flib_dictionary.on_tick()
|
||
</code></pre>
|
||
<hr />
|
||
<h1>flib_dictionary_global</h1>
|
||
<hr />
|
||
<h1>flib_direction</h1>
|
||
<p>Functions for working with directions.</p>
|
||
<pre><code class="language-lua">local flib_direction = require("__flib__/direction")
|
||
</code></pre>
|
||
<h2>east</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>defines.direction.east</p>
|
||
<h2>from_positions</h2>
|
||
<pre><code class="language-lua">function flib_direction.from_positions(source: MapPosition.0|MapPosition.1, target: MapPosition.0|MapPosition.1, round?: boolean)
|
||
-> defines.direction
|
||
</code></pre>
|
||
<p>Calculate the direction of travel from the source to the target.</p>
|
||
<p>@<em>param</em> <code>round</code> — If true, round to the nearest <code>defines.direction</code>.</p>
|
||
<h2>next</h2>
|
||
<pre><code class="language-lua">function flib_direction.next(direction: defines.direction, eight_way?: boolean)
|
||
-> defines.direction
|
||
</code></pre>
|
||
<p>Calculate the next four-way or eight-way direction.</p>
|
||
<h2>north</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>defines.direction.north</p>
|
||
<h2>northeast</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>defines.direction.northeast</p>
|
||
<h2>northwest</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>defines.direction.northwest</p>
|
||
<h2>opposite</h2>
|
||
<pre><code class="language-lua">function flib_direction.opposite(direction: defines.direction)
|
||
-> defines.direction
|
||
</code></pre>
|
||
<p>Calculate the opposite direction.</p>
|
||
<h2>previous</h2>
|
||
<pre><code class="language-lua">function flib_direction.previous(direction: defines.direction, eight_way?: boolean)
|
||
-> defines.direction
|
||
</code></pre>
|
||
<p>Calculate the previous four-way or eight-way direction.</p>
|
||
<h2>south</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>defines.direction.south</p>
|
||
<h2>southeast</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>defines.direction.southeast</p>
|
||
<h2>southwest</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>defines.direction.southwest</p>
|
||
<h2>to_orientation</h2>
|
||
<pre><code class="language-lua">function flib_direction.to_orientation(direction: defines.direction)
|
||
-> number
|
||
</code></pre>
|
||
<p>Calculate an orientation from a direction.</p>
|
||
<h2>to_vector</h2>
|
||
<pre><code class="language-lua">function flib_direction.to_vector(direction: defines.direction, distance?: number)
|
||
-> MapPosition.0|MapPosition.1
|
||
</code></pre>
|
||
<p>Calculate a vector from a direction.</p>
|
||
<p>@<em>param</em> <code>distance</code> — default: <code>1</code></p>
|
||
<h2>to_vector_2d</h2>
|
||
<pre><code class="language-lua">function flib_direction.to_vector_2d(direction: defines.direction, longitudinal: number, orthogonal: number)
|
||
-> (MapPosition.0|MapPosition.1)?
|
||
</code></pre>
|
||
<p>Calculate a two-dimensional vector from a cardinal direction.</p>
|
||
<p>@<em>param</em> <code>longitudinal</code> — Distance to move in the specified direction.</p>
|
||
<p>@<em>param</em> <code>orthogonal</code> — Distance to move perpendicular to the specified direction. A negative distance will move "left" and a positive distance will move "right" from the perspective of the direction.</p>
|
||
<h2>west</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>defines.direction.west</p>
|
||
<hr />
|
||
<h1>flib_format</h1>
|
||
<p>Various string formatting functions.</p>
|
||
<pre><code class="language-lua">local flib_format = require("__flib__/format")
|
||
</code></pre>
|
||
<h2>number</h2>
|
||
<pre><code class="language-lua">function flib_format.number(amount: number, append_suffix?: boolean, fixed_precision?: number)
|
||
-> string
|
||
</code></pre>
|
||
<p>Format a number for display, adding commas and an optional SI suffix.
|
||
Specify <code>fixed_precision</code> to display the number with the given width,
|
||
adjusting precision as necessary.</p>
|
||
<h2>time</h2>
|
||
<pre><code class="language-lua">function flib_format.time(tick?: integer, include_leading_zeroes?: boolean)
|
||
-> string
|
||
</code></pre>
|
||
<p>Convert the given tick or game.tick into "[hh:]mm:ss" format.</p>
|
||
<hr />
|
||
<h1>flib_gui</h1>
|
||
<p>Utilities for building GUIs and handling GUI events.</p>
|
||
<pre><code class="language-lua">local flib_gui = require("__flib__/gui-lite")
|
||
</code></pre>
|
||
<h2>add</h2>
|
||
<pre><code class="language-lua">function flib_gui.add(parent: LuaGuiElement, def: GuiElemDefClass|GuiElemDefClass|GuiElemDefClass[]|GuiElemDef|GuiElemDefClass[][]|GuiElemDefClass|GuiElemDefClass|GuiElemDefClass[]|GuiElemDef|GuiElemDefClass[][]|GuiElemDef|GuiElemDefClass[][], elems?: table<string, LuaGuiElement>)
|
||
-> elems: table<string, LuaGuiElement>
|
||
2. first: LuaGuiElement
|
||
</code></pre>
|
||
<p>Add a new child or children to the given GUI element.</p>
|
||
<p>@<em>param</em> <code>def</code> — Can be a single element, or an array of elements.</p>
|
||
<p>@<em>param</em> <code>elems</code> — Optional initial <code>elems</code> table.</p>
|
||
<p>@<em>return</em> <code>elems</code> — Elements with names will be collected into this table.</p>
|
||
<p>@<em>return</em> <code>first</code> — The element that was created first; the "top level" element.</p>
|
||
<h2>add_handlers</h2>
|
||
<pre><code class="language-lua">function flib_gui.add_handlers(new_handlers: table<string, fun(e: EventData.on_gui_checked_state_changed|EventData.on_gui_click|EventData.on_gui_closed|EventData.on_gui_confirmed|EventData.on_gui_elem_changed...(+7))>, wrapper?: fun(e: EventData.on_gui_checked_state_changed|EventData.on_gui_click|EventData.on_gui_closed|EventData.on_gui_confirmed|EventData.on_gui_elem_changed...(+7), handler: function))
|
||
</code></pre>
|
||
<p>Add the given handler functions to the registry for use with <code>flib_gui.add</code>. Each handler must have a unique name. If a
|
||
<code>wrapper</code> function is provided, it will be called instead, and will receive the event data and handler. The wrapper
|
||
can be used to execute logic or gather data common to all handler functions for this GUI.</p>
|
||
<h2>dispatch</h2>
|
||
<pre><code class="language-lua">function flib_gui.dispatch(e: EventData.on_gui_checked_state_changed|EventData.on_gui_click|EventData.on_gui_closed|EventData.on_gui_confirmed|EventData.on_gui_elem_changed...(+7))
|
||
-> handled: boolean
|
||
</code></pre>
|
||
<p>Dispatch the handler associated with this event and GUI element. The handler must have been added using
|
||
<code>flib_gui.add_handlers</code>.</p>
|
||
<p>@<em>return</em> <code>handled</code> — True if an event handler was called.</p>
|
||
<h2>events</h2>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<p>For use with <code>__core__/lualib/event_handler</code>. Pass <code>flib_gui</code> into <code>handler.add_lib</code> to handle
|
||
all GUI events automatically.</p>
|
||
<h2>handle_events</h2>
|
||
<pre><code class="language-lua">function flib_gui.handle_events()
|
||
</code></pre>
|
||
<p>Handle all GUI events with <code>flib_gui.dispatch</code>. Will not overwrite any existing event handlers.</p>
|
||
<hr />
|
||
<h1>flib_math</h1>
|
||
<p>Extension of the Lua 5.2 math library.</p>
|
||
<pre><code class="language-lua">local flib_math = require("__flib__/math")
|
||
</code></pre>
|
||
<h2>ceil_to</h2>
|
||
<pre><code class="language-lua">function flib_math.ceil_to(num: number, num_decimals: number)
|
||
-> number
|
||
</code></pre>
|
||
<p>Ceil a number to N decimal places.
|
||
Use <code>math.ceil</code> directly if no decimals are needed.</p>
|
||
<h2>ceiled</h2>
|
||
<pre><code class="language-lua">function flib_math.ceiled(num: number, divisor?: number)
|
||
-> number
|
||
</code></pre>
|
||
<p>Ceil a number to the nearest multiple of divisor.</p>
|
||
<p>@<em>param</em> <code>divisor</code> — <code>num</code> will be ceiled to the nearest multiple of <code>divisor</code> (default: 1).</p>
|
||
<h2>clamp</h2>
|
||
<pre><code class="language-lua">function flib_math.clamp(x: number, min?: number, max?: number)
|
||
-> number
|
||
</code></pre>
|
||
<p>Clamp a number between minimum and maximum values.</p>
|
||
<p>@<em>param</em> <code>min</code> — default 0</p>
|
||
<p>@<em>param</em> <code>max</code> — default 1</p>
|
||
<h2>deg_to_rad</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<p>Multiply by degrees to convert to radians.</p>
|
||
<pre><code class="language-lua">local rad = 1 x flib_math.deg_to_rad -- 0.0174533
|
||
</code></pre>
|
||
<h2>floor_to</h2>
|
||
<pre><code class="language-lua">function flib_math.floor_to(num: number, num_decimals: number)
|
||
-> number
|
||
</code></pre>
|
||
<p>Floor a number to N decimal places.
|
||
Use <code>math.floor</code> directly if no decimals are needed.</p>
|
||
<h2>floored</h2>
|
||
<pre><code class="language-lua">function flib_math.floored(num: number, divisor?: number)
|
||
-> number
|
||
</code></pre>
|
||
<p>Floor a number to the nearest multiple of divisor.</p>
|
||
<p>@<em>param</em> <code>divisor</code> — <code>num</code> will be floored to the nearest multiple of <code>divisor</code> (default: 1).</p>
|
||
<h2>lerp</h2>
|
||
<pre><code class="language-lua">function flib_math.lerp(num1: number, num2: number, amount: number)
|
||
-> number
|
||
</code></pre>
|
||
<p>Linearly interpolate between <code>num1</code> and <code>num2</code> by <code>amount</code>.</p>
|
||
<p>The parameter <code>amount</code> is clamped between <code>0</code> and <code>1</code>.</p>
|
||
<p>When <code>amount = 0</code>, returns <code>num1</code>.</p>
|
||
<p>When <code>amount = 1</code>, returns <code>num2</code>.</p>
|
||
<p>When <code>amount = 0.5</code>, returns the midpoint of <code>num1</code> and <code>num2</code>.</p>
|
||
<h2>max_double</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<h2>max_int</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>2,147,483,647</p>
|
||
<h2>max_int16</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>32,767</p>
|
||
<h2>max_int53</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>9,007,199,254,740,991</p>
|
||
<h2>max_int8</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>127</p>
|
||
<h2>max_uint</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>4,294,967,295</p>
|
||
<h2>max_uint16</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>65,535</p>
|
||
<h2>max_uint8</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>255</p>
|
||
<h2>maximum</h2>
|
||
<pre><code class="language-lua">function flib_math.maximum(set: number[])
|
||
-> number
|
||
</code></pre>
|
||
<p>Returns the argument with the maximum value from a set.</p>
|
||
<h2>mean</h2>
|
||
<pre><code class="language-lua">function flib_math.mean(set: number[])
|
||
-> number
|
||
</code></pre>
|
||
<p>Calculate the mean (average) of a set of numbers.</p>
|
||
<h2>midrange</h2>
|
||
<pre><code class="language-lua">function flib_math.midrange(set: number[])
|
||
-> number
|
||
</code></pre>
|
||
<p>Calculate the mean of the largest and the smallest values in a set of numbers.</p>
|
||
<h2>min_double</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<h2>min_int</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>-2,147,483,648</p>
|
||
<h2>min_int16</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>-32,768</p>
|
||
<h2>min_int53</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>-9,007,199,254,740,992</p>
|
||
<h2>min_int8</h2>
|
||
<pre><code class="language-lua">integer
|
||
</code></pre>
|
||
<p>-128</p>
|
||
<h2>minimum</h2>
|
||
<pre><code class="language-lua">function flib_math.minimum(set: number[])
|
||
-> number
|
||
</code></pre>
|
||
<p>Returns the argument with the minimum value from a set.</p>
|
||
<h2>rad_to_deg</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<p>Multiply by radians to convert to degrees.</p>
|
||
<pre><code class="language-lua">local deg = 1 x flib_math.rad_to_deg -- 57.2958
|
||
</code></pre>
|
||
<h2>range</h2>
|
||
<pre><code class="language-lua">function flib_math.range(set: number[])
|
||
-> number
|
||
</code></pre>
|
||
<p>Calculate the range in a set of numbers.</p>
|
||
<h2>round</h2>
|
||
<pre><code class="language-lua">function flib_math.round(num: number, divisor?: number)
|
||
-> number
|
||
</code></pre>
|
||
<p>Round a number to the nearest multiple of divisor.
|
||
Defaults to nearest integer if divisor is not provided.</p>
|
||
<p>From <a href="http://lua-users.org/wiki/SimpleRound">lua-users.org</a>.</p>
|
||
<p>@<em>param</em> <code>divisor</code> — <code>num</code> will be rounded to the nearest multiple of <code>divisor</code> (default: 1).</p>
|
||
<h2>round_to</h2>
|
||
<pre><code class="language-lua">function flib_math.round_to(num: number, num_decimals: number)
|
||
-> number
|
||
</code></pre>
|
||
<p>Round a number to the nearest N decimal places.</p>
|
||
<p>From <a href="http://lua-users.org/wiki/SimpleRound">lua-users.org</a>.</p>
|
||
<h2>sign</h2>
|
||
<pre><code class="language-lua">function flib_math.sign(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<p>Return the signedness of a number as a multiplier.</p>
|
||
<h2>sum</h2>
|
||
<pre><code class="language-lua">function flib_math.sum(set: number[])
|
||
-> number
|
||
</code></pre>
|
||
<p>Calculate the sum of a set of numbers.</p>
|
||
<hr />
|
||
<h1>flib_migration</h1>
|
||
<p>Mod migration and version comparison functions.</p>
|
||
<pre><code class="language-lua">local flib_migration = require("__flib__/migration")
|
||
</code></pre>
|
||
<h2>format_version</h2>
|
||
<pre><code class="language-lua">function flib_migration.format_version(version: string, format?: string)
|
||
-> string?
|
||
</code></pre>
|
||
<p>Normalize version strings for easy comparison.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">migration.format_version("1.10.1234", "%04d")
|
||
migration.format_version("3", "%02d")
|
||
</code></pre>
|
||
<p>@<em>param</em> <code>format</code> — default: <code>%02d</code></p>
|
||
<h2>handle_on_configuration_changed</h2>
|
||
<pre><code class="language-lua">function flib_migration.handle_on_configuration_changed(version_migrations?: table<string, fun(...any)>, generic_handler?: fun(e: ConfigurationChangedData))
|
||
</code></pre>
|
||
<p>Handle on_configuration_changed with the given generic and version-specific migrations. Will override any existing
|
||
on_configuration_changed event handler. Both arguments are optional.</p>
|
||
<h2>is_newer_version</h2>
|
||
<pre><code class="language-lua">function flib_migration.is_newer_version(old_version: string, current_version: string, format?: string)
|
||
-> boolean?
|
||
</code></pre>
|
||
<p>Check if current_version is newer than old_version.</p>
|
||
<p>@<em>param</em> <code>format</code> — default: <code>%02d</code></p>
|
||
<h2>on_config_changed</h2>
|
||
<pre><code class="language-lua">function flib_migration.on_config_changed(e: ConfigurationChangedData, migrations?: table<string, fun(...any)>, mod_name?: string, ...any)
|
||
-> run_generic_micrations: boolean
|
||
</code></pre>
|
||
<p>Determine if migrations need to be run for this mod, then run them if needed.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">script.on_configuration_changed(function(e)
|
||
if migration.on_config_changed(e, migrations) then
|
||
-- Run generic (non-init) migrations
|
||
rebuild_prototype_data()
|
||
end
|
||
end
|
||
</code></pre>
|
||
<p>@<em>param</em> <code>mod_name</code> — The mod to check against. Defaults to the current mod.</p>
|
||
<p>@<em>param</em> <code>...</code> — All additional arguments will be passed to each function within <code>migrations</code>.</p>
|
||
<h2>run</h2>
|
||
<pre><code class="language-lua">function flib_migration.run(old_version: string, migrations: table<string, fun(...any)>, format?: string, ...any)
|
||
</code></pre>
|
||
<p>Run migrations against the given version.</p>
|
||
<p>@<em>param</em> <code>format</code> — default: <code>%02d</code></p>
|
||
<p>@<em>param</em> <code>...</code> — All additional arguments will be passed to each function within <code>migrations</code>.</p>
|
||
<hr />
|
||
<h1>flib_on_tick_n</h1>
|
||
<p>Schedule tasks to be executed later.</p>
|
||
<pre><code class="language-lua">local flib_on_tick_n = require("__flib__/on-tick-n")
|
||
</code></pre>
|
||
<h2>add</h2>
|
||
<pre><code class="language-lua">function flib_on_tick_n.add(tick: number, task: any)
|
||
-> ident: TaskIdent
|
||
</code></pre>
|
||
<p>Add a task to execute on the given tick.</p>
|
||
<p>@<em>param</em> <code>task</code> — The data representing this task. This can be anything except for a <code>function</code>.</p>
|
||
<p>@<em>return</em> <code>ident</code> — An identifier for the task. Save this if you might remove the task before execution.</p>
|
||
<h2>init</h2>
|
||
<pre><code class="language-lua">function flib_on_tick_n.init()
|
||
</code></pre>
|
||
<p>Initialize the module's script data table.</p>
|
||
<p>Must be called at the <strong>beginning</strong> of <code>on_init</code>. Can also be used to delete all current tasks.</p>
|
||
<h2>remove</h2>
|
||
<pre><code class="language-lua">function flib_on_tick_n.remove(ident: TaskIdent)
|
||
-> boolean
|
||
</code></pre>
|
||
<p>Remove a scheduled task.</p>
|
||
<p>@<em>param</em> <code>ident</code> — The identifier object for the task, as returned from <code>on-tick-n.add</code>.</p>
|
||
<h2>retrieve</h2>
|
||
<pre><code class="language-lua">function flib_on_tick_n.retrieve(tick: number)
|
||
-> table<number, any>?
|
||
</code></pre>
|
||
<p>Retrieve the tasks for the given tick, if any.</p>
|
||
<p>Must be called <strong>during</strong> <code>on_tick</code>.</p>
|
||
<hr />
|
||
<h1>flib_orientation</h1>
|
||
<p>Functions for working with orientations.</p>
|
||
<pre><code class="language-lua">local flib_orientation = require("__flib__/orientation")
|
||
</code></pre>
|
||
<h2>add</h2>
|
||
<pre><code class="language-lua">function flib_orientation.add(orientation1: number, orientation2: number)
|
||
-> the: number
|
||
</code></pre>
|
||
<p>Add two orientations together.</p>
|
||
<p>@<em>return</em> <code>the</code> — orientations added together</p>
|
||
<h2>east</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<h2>north</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<h2>northeast</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<h2>northwest</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<h2>opposite</h2>
|
||
<pre><code class="language-lua">function flib_orientation.opposite(orientation: number)
|
||
-> number
|
||
</code></pre>
|
||
<p>Returns the opposite orientation.</p>
|
||
<h2>south</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<h2>southeast</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<h2>southwest</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<h2>to_direction</h2>
|
||
<pre><code class="language-lua">function flib_orientation.to_direction(orientation: number, eight_way: boolean)
|
||
-> defines.direction
|
||
</code></pre>
|
||
<p>Returns a 4way or 8way direction from an orientation.</p>
|
||
<h2>west</h2>
|
||
<pre><code class="language-lua">number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>flib_position</h1>
|
||
<p>Utilities for manipulating positions. All functions support both the shorthand and explicit syntaxes and will
|
||
preserve the syntax that was passed in.</p>
|
||
<pre><code class="language-lua">local flib_position = require("__flib__/position")
|
||
</code></pre>
|
||
<h2>add</h2>
|
||
<pre><code class="language-lua">function flib_position.add(pos1: <P>, pos2: <P>)
|
||
-> <P>
|
||
</code></pre>
|
||
<p>Add two positions.</p>
|
||
<h2>ceil</h2>
|
||
<pre><code class="language-lua">function flib_position.ceil(pos: <P>)
|
||
-> <P>
|
||
</code></pre>
|
||
<p>Ceil the given position.</p>
|
||
<h2>distance</h2>
|
||
<pre><code class="language-lua">function flib_position.distance(pos1: <P>, pos2: <P>)
|
||
-> number
|
||
</code></pre>
|
||
<p>Calculate the distance between two positions.</p>
|
||
<h2>distance_squared</h2>
|
||
<pre><code class="language-lua">function flib_position.distance_squared(pos1: <P>, pos2: <P>)
|
||
-> number
|
||
</code></pre>
|
||
<p>Calculate the squared distance between two positions.</p>
|
||
<h2>div</h2>
|
||
<pre><code class="language-lua">function flib_position.div(pos1: <P>, pos2: <P>)
|
||
-> <P>
|
||
</code></pre>
|
||
<p>Divide two positions.</p>
|
||
<h2>ensure_explicit</h2>
|
||
<pre><code class="language-lua">function flib_position.ensure_explicit(pos: <P>)
|
||
-> <P>
|
||
</code></pre>
|
||
<p>Return the position in explicit form.</p>
|
||
<h2>ensure_short</h2>
|
||
<pre><code class="language-lua">function flib_position.ensure_short(pos: <P>)
|
||
-> <P>
|
||
</code></pre>
|
||
<p>Return the position in shorthand form.</p>
|
||
<h2>eq</h2>
|
||
<pre><code class="language-lua">function flib_position.eq(pos1: <P>, pos2: <P>)
|
||
-> boolean
|
||
</code></pre>
|
||
<p>Test if two positions are equal.</p>
|
||
<h2>floor</h2>
|
||
<pre><code class="language-lua">function flib_position.floor(pos: <P>)
|
||
-> <P>
|
||
</code></pre>
|
||
<p>Floor the given position.</p>
|
||
<h2>from_chunk</h2>
|
||
<pre><code class="language-lua">function flib_position.from_chunk(pos: ChunkPosition.0|ChunkPosition.1)
|
||
-> TilePosition.0|TilePosition.1
|
||
</code></pre>
|
||
<p>Convert a <code>ChunkPosition</code> into a <code>TilePosition</code> by multiplying by 32.</p>
|
||
<h2>ge</h2>
|
||
<pre><code class="language-lua">function flib_position.ge(pos1: <P>, pos2: <P>)
|
||
-> boolean
|
||
</code></pre>
|
||
<p>Test if <code>pos1</code> is greater than or equal to <code>pos2</code>.</p>
|
||
<h2>gt</h2>
|
||
<pre><code class="language-lua">function flib_position.gt(pos1: <P>, pos2: <P>)
|
||
-> boolean
|
||
</code></pre>
|
||
<p>Test if <code>pos1</code> is greater than <code>pos2</code>.</p>
|
||
<h2>le</h2>
|
||
<pre><code class="language-lua">function flib_position.le(pos1: <P>, pos2: <P>)
|
||
-> boolean
|
||
</code></pre>
|
||
<p>Test if <code>pos1</code> is less than or equal to <code>pos2</code>.</p>
|
||
<h2>lerp</h2>
|
||
<pre><code class="language-lua">function flib_position.lerp(pos1: <P>, pos2: <P>, amount: number)
|
||
-> <P>
|
||
</code></pre>
|
||
<p>Linearly interpolate between two positions. For example, an amount of 0.5 will return the midpoint.</p>
|
||
<h2>lt</h2>
|
||
<pre><code class="language-lua">function flib_position.lt(pos1: <P>, pos2: <P>)
|
||
-> boolean
|
||
</code></pre>
|
||
<p>Test if <code>pos1</code> is less than <code>pos2</code>.</p>
|
||
<h2>mod</h2>
|
||
<pre><code class="language-lua">function flib_position.mod(pos1: <P>, pos2: <P>)
|
||
-> <P>
|
||
</code></pre>
|
||
<p>Take the remainder (modulus) of two positions.</p>
|
||
<h2>mul</h2>
|
||
<pre><code class="language-lua">function flib_position.mul(pos1: <P>, pos2: <P>)
|
||
-> <P>
|
||
</code></pre>
|
||
<p>Multiply two positions.</p>
|
||
<h2>pow</h2>
|
||
<pre><code class="language-lua">function flib_position.pow(pos1: <P>, pos2: <P>)
|
||
-> <P>
|
||
</code></pre>
|
||
<p>Take the power of two positions. <code>pos1^pos2</code>.</p>
|
||
<h2>sub</h2>
|
||
<pre><code class="language-lua">function flib_position.sub(pos1: <P>, pos2: <P>)
|
||
-> <P>
|
||
</code></pre>
|
||
<p>Subtract two positions.</p>
|
||
<h2>to_chunk</h2>
|
||
<pre><code class="language-lua">function flib_position.to_chunk(pos: MapPosition.0|MapPosition.1|TilePosition.0|TilePosition.1)
|
||
-> ChunkPosition.0|ChunkPosition.1
|
||
</code></pre>
|
||
<p>Convert a <code>MapPosition</code> or <code>TilePosition</code> into a <code>ChunkPosition</code> by dividing by 32 and flooring.</p>
|
||
<h2>to_tile</h2>
|
||
<pre><code class="language-lua">function flib_position.to_tile(pos: MapPosition.0|MapPosition.1)
|
||
-> TilePosition.0|TilePosition.1
|
||
</code></pre>
|
||
<p>Convert a <code>MapPosition</code> into a <code>TilePosition</code> by flooring.</p>
|
||
<hr />
|
||
<h1>flib_queue</h1>
|
||
<p>Lua queue implementation.</p>
|
||
<p>Based on "Queues and Double Queues" from <a href="http://www.lua.org/pil/11.4.html">Programming in Lua</a>.</p>
|
||
<pre><code class="language-lua">local flib_queue = require("__flib__/queue")
|
||
</code></pre>
|
||
<h2>iter</h2>
|
||
<pre><code class="language-lua">function flib_queue.iter(self: Queue<<T>>)
|
||
-> fun(self: Queue<<T>>, index: integer):<T>
|
||
</code></pre>
|
||
<p>Iterate over a queue's elements from the beginning to the end.</p>
|
||
<h1>Example</h1>
|
||
<pre><code class="language-lua">local my_queue = queue.new()
|
||
for i = 1, 10 do
|
||
queue.push_back(my_queue, 1)
|
||
end
|
||
|
||
-- 1 2 3 4 5 6 7 8 9 10
|
||
for num in queue.iter(my_queue) do
|
||
log(i)
|
||
end
|
||
</code></pre>
|
||
<h2>iter_left</h2>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<h2>iter_rev</h2>
|
||
<pre><code class="language-lua">function flib_queue.iter_rev(self: Queue<<T>>)
|
||
-> fun(self: Queue<<T>>, index: integer):<T>
|
||
</code></pre>
|
||
<p>Iterate over a queue's elements from the end to the beginning.</p>
|
||
<h1>Example</h1>
|
||
<pre><code class="language-lua">local my_queue = queue.new()
|
||
for i = 1, 10 do
|
||
queue.push_back(my_queue, 1)
|
||
end
|
||
|
||
-- 10 9 8 7 6 5 4 3 2 1
|
||
for num in queue.iter_rev(my_queue) do
|
||
log(i)
|
||
end
|
||
</code></pre>
|
||
<h2>iter_right</h2>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<h2>length</h2>
|
||
<pre><code class="language-lua">function flib_queue.length(self: Queue<<T>>)
|
||
-> number
|
||
</code></pre>
|
||
<p>Get the length of the queue.</p>
|
||
<h2>new</h2>
|
||
<pre><code class="language-lua">function flib_queue.new()
|
||
-> Queue
|
||
</code></pre>
|
||
<p>Create a new queue.</p>
|
||
<h2>pop_back</h2>
|
||
<pre><code class="language-lua">function flib_queue.pop_back(self: Queue<<T>>)
|
||
-> <T>?
|
||
</code></pre>
|
||
<p>Retrieve an element from the back of the queue.</p>
|
||
<h2>pop_front</h2>
|
||
<pre><code class="language-lua">function flib_queue.pop_front(self: Queue<<T>>)
|
||
-> <T>?
|
||
</code></pre>
|
||
<p>Retrieve an element from the front of the queue.</p>
|
||
<h2>pop_left</h2>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<h2>pop_right</h2>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<h2>push_back</h2>
|
||
<pre><code class="language-lua">function flib_queue.push_back(self: Queue<<T>>, value: <T>)
|
||
</code></pre>
|
||
<p>Push an element into the back of the queue.</p>
|
||
<h2>push_front</h2>
|
||
<pre><code class="language-lua">function flib_queue.push_front(self: Queue<<T>>, value: <T>)
|
||
</code></pre>
|
||
<p>Push an element into the front of the queue.</p>
|
||
<h2>push_left</h2>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<h2>push_right</h2>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<hr />
|
||
<h1>flib_table</h1>
|
||
<p>Extension of the Lua 5.2 table library.</p>
|
||
<p><strong>NOTE:</strong> Several functions in this module will only work with <a href="https://www.lua.org/pil/11.1.html">arrays</a>,
|
||
which are tables with sequentially numbered keys. All table functions will work with arrays as well, but
|
||
array functions <strong>will not</strong> work with tables.</p>
|
||
<pre><code class="language-lua">local flib_table: = require("__flib__/table")
|
||
</code></pre>
|
||
<h2>array_copy</h2>
|
||
<pre><code class="language-lua">function flib_table.array_copy(arr: Array)
|
||
-> Array
|
||
</code></pre>
|
||
<p>Shallow copy an array's values into a new array.</p>
|
||
<p>This function is optimized specifically for arrays, and should be used in place of <code>table.shallow_copy</code> for arrays.</p>
|
||
<h2>array_merge</h2>
|
||
<pre><code class="language-lua">function flib_table.array_merge(arrays: Array)
|
||
-> Array
|
||
</code></pre>
|
||
<p>Merge all of the given arrays into a single array.</p>
|
||
<p>@<em>param</em> <code>arrays</code> — An array of arrays to merge.</p>
|
||
<h2>deep_compare</h2>
|
||
<pre><code class="language-lua">function flib_table.deep_compare(tbl1: table, tbl2: table)
|
||
-> boolean
|
||
</code></pre>
|
||
<p>Recursively compare two tables for inner equality.</p>
|
||
<p>Does not compare metatables.</p>
|
||
<h2>deep_copy</h2>
|
||
<pre><code class="language-lua">function flib_table.deep_copy(tbl: <T>)
|
||
-> <T>
|
||
</code></pre>
|
||
<p>Recursively copy the contents of a table into a new table.</p>
|
||
<p>Does not create new copies of Factorio objects.</p>
|
||
<p>@<em>param</em> <code>tbl</code> — The table to make a copy of.</p>
|
||
<h2>deep_merge</h2>
|
||
<pre><code class="language-lua">function flib_table.deep_merge(tables: Array)
|
||
-> table
|
||
</code></pre>
|
||
<p>Recursively merge two or more tables.</p>
|
||
<p>Values from earlier tables are overwritten by values from later tables, unless both values are tables, in which case
|
||
they are recursively merged.</p>
|
||
<p>Non-merged tables are deep-copied, so the result is brand-new.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">local tbl = {foo = "bar"}
|
||
log(tbl.foo) -- logs "bar"
|
||
log (tbl.bar) -- errors (key is nil)
|
||
tbl = table.merge{tbl, {foo = "baz", set = 3}}
|
||
log(tbl.foo) -- logs "baz"
|
||
log(tbl.set) -- logs "3"
|
||
</code></pre>
|
||
<p>@<em>param</em> <code>tables</code> — An array of tables to merge.</p>
|
||
<h2>filter</h2>
|
||
<pre><code class="language-lua">function flib_table.filter(tbl: table<<K>, <V>>, filter: fun(value: <V>, key: <K>):boolean, array_insert?: boolean)
|
||
-> table<<K>, <V>>
|
||
</code></pre>
|
||
<p>Create a filtered version of a table based on the results of a filter function.</p>
|
||
<p>Calls <code>filter(value, key)</code> on each element in the table, returning a new table with only pairs for which
|
||
<code>filter</code> returned a truthy value.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">local tbl = {1, 2, 3, 4, 5, 6}
|
||
local just_evens = table.filter(tbl, function(v) return v % 2 == 0 end) -- {[2] = 2, [4] = 4, [6] = 6}
|
||
local just_evens_arr = table.filter(tbl, function(v) return v % 2 == 0 end, true) -- {2, 4, 6}
|
||
</code></pre>
|
||
<p>@<em>param</em> <code>array_insert</code> — If true, the result will be constructed as an array of values that matched the filter. Key references will be lost.</p>
|
||
<h2>find</h2>
|
||
<pre><code class="language-lua">function flib_table.find(tbl: table<<K>, <V>>, value: <V>)
|
||
-> key: <K>?
|
||
</code></pre>
|
||
<p>Find and return the first key containing the given value.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">local tbl = {"foo", "bar"}
|
||
local key_of_foo = table.find(tbl, "foo") -- 1
|
||
local key_of_baz = table.find(tbl, "baz") -- nil
|
||
</code></pre>
|
||
<p>@<em>param</em> <code>tbl</code> — The table to search.</p>
|
||
<p>@<em>param</em> <code>value</code> — The value to match. Must have an <code>eq</code> metamethod set, otherwise will error.</p>
|
||
<p>@<em>return</em> <code>key</code> — The first key corresponding to <code>value</code>, if any.</p>
|
||
<h2>for_each</h2>
|
||
<pre><code class="language-lua">function flib_table.for_each(tbl: table<<K>, <V>>, callback: fun(value: <V>, key: <K>):boolean)
|
||
-> Whether: boolean
|
||
</code></pre>
|
||
<p>Call the given function for each item in the table, and abort if the function returns truthy.</p>
|
||
<p>Calls <code>callback(value, key)</code> for each item in the table, and immediately ceases iteration if the callback returns truthy.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">local tbl = {1, 2, 3, 4, 5}
|
||
-- Run a function for each item (identical to a standard FOR loop)
|
||
table.for_each(tbl, function(v) game.print(v) end)
|
||
-- Determine if any value in the table passes the test
|
||
local value_is_even = table.for_each(tbl, function(v) return v % 2 == 0 end)
|
||
-- Determine if ALL values in the table pass the test (invert the test result and function return)
|
||
local all_values_less_than_six = not table.for_each(tbl, function(v) return not (v < 6) end)
|
||
</code></pre>
|
||
<p>@<em>param</em> <code>callback</code> — Receives <code>value</code> and <code>key</code> as parameters.</p>
|
||
<p>@<em>return</em> <code>Whether</code> — the callback returned truthy for any one item, and thus halted iteration.</p>
|
||
<h2>for_n_of</h2>
|
||
<pre><code class="language-lua">function flib_table.for_n_of(tbl: table<<K>, <V>>, from_k: <K>, n: number, callback: fun(value: <V>, key: <K>):<C>, boolean, boolean, _next?: fun(tbl: table<<K>, <V>>, from_k: <K>):<K>, <V>)
|
||
-> next_key: <K>?
|
||
2. results: table<<K>, <C>>
|
||
3. reached_end: boolean
|
||
</code></pre>
|
||
<p>Call the given function on a set number of items in a table, returning the next starting key.</p>
|
||
<p>Calls <code>callback(value, key)</code> over <code>n</code> items from <code>tbl</code>, starting after <code>from_k</code>.</p>
|
||
<p>The first return value of each invocation of <code>callback</code> will be collected and returned in a table keyed by the
|
||
current item's key.</p>
|
||
<p>The second return value of <code>callback</code> is a flag requesting deletion of the current item.</p>
|
||
<p>The third return value of <code>callback</code> is a flag requesting that the iteration be immediately aborted. Use this flag to
|
||
early return on some condition in <code>callback</code>. When aborted, <code>for_n_of</code> will return the previous key as <code>from_k</code>, so
|
||
the next call to <code>for_n_of</code> will restart on the key that was aborted (unless it was also deleted).</p>
|
||
<p><strong>DO NOT</strong> delete entires from <code>tbl</code> from within <code>callback</code>, this will break the iteration. Use the deletion flag
|
||
instead.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">local extremely_large_table = {
|
||
[1000] = 1,
|
||
[999] = 2,
|
||
[998] = 3,
|
||
...,
|
||
[2] = 999,
|
||
[1] = 1000,
|
||
}
|
||
event.on_tick(function()
|
||
global.from_k = table.for_n_of(extremely_large_table, global.from_k, 10, function(v) game.print(v) end)
|
||
end)
|
||
</code></pre>
|
||
<p>@<em>param</em> <code>tbl</code> — The table to iterate over.</p>
|
||
<p>@<em>param</em> <code>from_k</code> — The key to start iteration at, or <code>nil</code> to start at the beginning of <code>tbl</code>. If the key does not exist in <code>tbl</code>, it will be treated as <code>nil</code>, <em>unless</em> a custom <code>_next</code> function is used.</p>
|
||
<p>@<em>param</em> <code>n</code> — The number of items to iterate.</p>
|
||
<p>@<em>param</em> <code>callback</code> — Receives <code>value</code> and <code>key</code> as parameters.</p>
|
||
<p>@<em>param</em> <code>_next</code> — A custom <code>next()</code> function. If not provided, the default <code>next()</code> will be used.</p>
|
||
<p>@<em>return</em> <code>next_key</code> — Where the iteration ended. Can be any valid table key, or <code>nil</code>. Pass this as <code>from_k</code> in the next call to <code>for_n_of</code> for <code>tbl</code>.</p>
|
||
<p>@<em>return</em> <code>results</code> — The results compiled from the first return of <code>callback</code>.</p>
|
||
<p>@<em>return</em> <code>reached_end</code> — Whether or not the end of the table was reached on this iteration.</p>
|
||
<h2>get_or_insert</h2>
|
||
<pre><code class="language-lua">function flib_table.get_or_insert(table: table<<K>, <V>>, key: <K>, default_value: <V>)
|
||
-> <V>
|
||
</code></pre>
|
||
<p>Retrieve the value at the key, or insert the default value.</p>
|
||
<h2>invert</h2>
|
||
<pre><code class="language-lua">function flib_table.invert(tbl: table<<K>, <V>>)
|
||
-> table<<V>, <K>>
|
||
</code></pre>
|
||
<p>Invert the given table such that <code>[value] = key</code>, returning a new table.</p>
|
||
<p>Non-unique values are overwritten based on the ordering from <code>pairs()</code>.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">local tbl = {"foo", "bar", "baz", set = "baz"}
|
||
local inverted = table.invert(tbl) -- {foo = 1, bar = 2, baz = "set"}
|
||
</code></pre>
|
||
<h2>map</h2>
|
||
<pre><code class="language-lua">function flib_table.map(tbl: table<<K>, <V>>, mapper: fun(value: <V>, key: <V>):<N>?)
|
||
-> table<<K>, <N>>
|
||
</code></pre>
|
||
<p>Create a transformed table using the output of a mapper function.</p>
|
||
<p>Calls <code>mapper(value, key)</code> on each element in the table, using the return as the new value for the key.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">local tbl = {1, 2, 3, 4, 5}
|
||
local tbl_times_ten = table.map(tbl, function(v) return v * 10 end) -- {10, 20, 30, 40, 50}
|
||
</code></pre>
|
||
<h2>partial_sort</h2>
|
||
<pre><code class="language-lua">function flib_table.partial_sort(arr: Array<<V>>, from_index?: number, iterations: number, comp: fun(a: <V>, b: <V>))
|
||
-> next_index: number?
|
||
</code></pre>
|
||
<p>Partially sort an array.</p>
|
||
<p>This function utilizes <a href="https://en.wikipedia.org/wiki/Insertion_sort">insertion sort</a>, which is <em>extremely</em> inefficient with large data sets. However, you can spread the sorting over multiple ticks, reducing the performance impact. Only use this function if <code>table.sort</code> is too slow.</p>
|
||
<p>@<em>param</em> <code>from_index</code> — The index to start iteration at (inclusive). Pass <code>nil</code> or a number less than <code>2</code> to begin at the start of the array.</p>
|
||
<p>@<em>param</em> <code>iterations</code> — The number of iterations to perform. Higher is more performance-heavy. This number should be adjusted based on the performance impact of the custom <code>comp</code> function (if any) and the size of the array.</p>
|
||
<p>@<em>param</em> <code>comp</code> — A comparison function for sorting. Must return truthy if <code>a < b</code>.</p>
|
||
<p>@<em>return</em> <code>next_index</code> — The index to start the next iteration at, or <code>nil</code> if the end was reached.</p>
|
||
<h2>reduce</h2>
|
||
<pre><code class="language-lua">function flib_table.reduce(tbl: table<<K>, <V>>, reducer: fun(acc: <R>, value: <V>, key: <K>):<R>, initial_value?: <R>)
|
||
-> <R>
|
||
</code></pre>
|
||
<p>"Reduce" a table's values into a single output value, using the results of a reducer function.</p>
|
||
<p>Calls <code>reducer(accumulator, value, key)</code> on each element in the table, returning a single accumulated output value.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">local tbl = {10, 20, 30, 40, 50}
|
||
local sum = table.reduce(tbl, function(acc, v) return acc + v end)
|
||
local sum_minus_ten = table.reduce(tbl, function(acc, v) return acc + v end, -10)
|
||
</code></pre>
|
||
<p>@<em>param</em> <code>initial_value</code> — The initial value for the accumulator. If not provided or is falsy, the first value in the table will be used as the initial <code>accumulator</code> value and skipped as <code>key</code>. Calling <code>reduce()</code> on an empty table without an <code>initial_value</code> will cause a crash.</p>
|
||
<h2>retrieve</h2>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<h2>shallow_copy</h2>
|
||
<pre><code class="language-lua">function flib_table.shallow_copy(tbl: <T>, use_rawset?: boolean)
|
||
-> The: <T>
|
||
</code></pre>
|
||
<p>Shallowly copy the contents of a table into a new table.</p>
|
||
<p>The parent table will have a new table reference, but any subtables within it will still have the same table
|
||
reference.</p>
|
||
<p>Does not copy metatables.</p>
|
||
<p>@<em>param</em> <code>use_rawset</code> — Use rawset to set the values (ignores metamethods).</p>
|
||
<p>@<em>return</em> <code>The</code> — copied table.</p>
|
||
<h2>shallow_merge</h2>
|
||
<pre><code class="language-lua">function flib_table.shallow_merge(tables: table[])
|
||
-> table
|
||
</code></pre>
|
||
<p>Shallowly merge two or more tables.
|
||
Unlike <code>table.deep_merge</code>, this will only combine the top level of the tables.</p>
|
||
<h2>size</h2>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<p>Retrieve the size of a table.</p>
|
||
<p>Uses Factorio's built-in <code>table_size</code> function.</p>
|
||
<h2>slice</h2>
|
||
<pre><code class="language-lua">function flib_table.slice(arr: Array<<V>>, start?: number, stop?: number)
|
||
-> A: Array<<V>>
|
||
</code></pre>
|
||
<p>Retrieve a shallow copy of a portion of an array, selected from <code>start</code> to <code>end</code> inclusive.</p>
|
||
<p>The original array <strong>will not</strong> be modified.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">local arr = {10, 20, 30, 40, 50, 60, 70, 80, 90}
|
||
local sliced = table.slice(arr, 3, 7) -- {30, 40, 50, 60, 70}
|
||
log(serpent.line(arr)) -- {10, 20, 30, 40, 50, 60, 70, 80, 90} (unchanged)
|
||
</code></pre>
|
||
<p>@<em>param</em> <code>start</code> — default: <code>1</code></p>
|
||
<p>@<em>param</em> <code>stop</code> — Stop at this index. If zero or negative, will stop <code>n</code> items from the end of the array (default: <code>#arr</code>).</p>
|
||
<p>@<em>return</em> <code>A</code> — new array with the copied values.</p>
|
||
<h2>splice</h2>
|
||
<pre><code class="language-lua">function flib_table.splice(arr: Array<<V>>, start: number, stop?: number)
|
||
-> A: Array<<V>>
|
||
</code></pre>
|
||
<p>Extract a portion of an array, selected from <code>start</code> to <code>end</code> inclusive.</p>
|
||
<p>The original array <strong>will</strong> be modified.</p>
|
||
<h3>Examples</h3>
|
||
<pre><code class="language-lua">local arr = {10, 20, 30, 40, 50, 60, 70, 80, 90}
|
||
local spliced = table.splice(arr, 3, 7) -- {30, 40, 50, 60, 70}
|
||
log(serpent.line(arr)) -- {10, 20, 80, 90} (values were removed)
|
||
</code></pre>
|
||
<p>@<em>param</em> <code>start</code> — default: <code>1</code></p>
|
||
<p>@<em>param</em> <code>stop</code> — Stop at this index. If zero or negative, will stop <code>n</code> items from the end of the array (default: <code>#arr</code>).</p>
|
||
<p>@<em>return</em> <code>A</code> — new array with the extracted values.</p>
|
||
<hr />
|
||
<h1>flib_train</h1>
|
||
<p>Functions for working with trains.</p>
|
||
<pre><code class="language-lua">local flib_train = require("__flib__/train")
|
||
</code></pre>
|
||
<h2>get_backer_name</h2>
|
||
<pre><code class="language-lua">function flib_train.get_backer_name(train: LuaTrain)
|
||
-> backer_name: string?
|
||
</code></pre>
|
||
<p>Get the backer_name of the main locomotive in a given train.</p>
|
||
<p>@<em>return</em> <code>backer_name</code> — The backer_name of the primary locomotive or <code>nil</code> when no locomotive was found</p>
|
||
<h2>get_composition_string</h2>
|
||
<pre><code class="language-lua">function flib_train.get_composition_string(train: LuaTrain)
|
||
-> composition: string?
|
||
2. TrainCompositionCounts?
|
||
</code></pre>
|
||
<p>Create a string representing train composition, and return a count of locomotives and wagons in the train.</p>
|
||
<ul>
|
||
<li><code><L<</code>, <code>>L></code>: Locomotives</li>
|
||
<li><code>C</code>: Cargo wagon</li>
|
||
<li><code>F</code>: Fluid wagon</li>
|
||
<li><code>A</code>: Artillery wagon</li>
|
||
</ul>
|
||
<p>@<em>return</em> <code>composition</code> — The composition string, or <code>nil</code> if the train was invalid.</p>
|
||
<p>@<em>return</em></p>
|
||
<h2>get_main_locomotive</h2>
|
||
<pre><code class="language-lua">function flib_train.get_main_locomotive(train: LuaTrain)
|
||
-> locomotive: LuaEntity?
|
||
</code></pre>
|
||
<p>Get the main locomotive in a given train.</p>
|
||
<p>@<em>return</em> <code>locomotive</code> — The primary locomotive entity or <code>nil</code> when no locomotive was found</p>
|
||
<h2>open_gui</h2>
|
||
<pre><code class="language-lua">function flib_train.open_gui(player_index: number, train: LuaTrain)
|
||
-> boolean
|
||
</code></pre>
|
||
<p>Open train GUI for one player.</p>
|
||
<p>@<em>return</em> — <code>true</code> if the GUI was opened.</p>
|
||
<h2>rotate_carriage</h2>
|
||
<pre><code class="language-lua">function flib_train.rotate_carriage(entity: LuaEntity)
|
||
-> rotated: boolean
|
||
</code></pre>
|
||
<p>Rotate a single carriage of a train.</p>
|
||
<p>@<em>return</em> <code>rotated</code> — <code>true</code> when rotation was successful.</p>
|
||
<hr />
|
||
<h1>game</h1>
|
||
<p><strong>Global Description:</strong><br />
|
||
The main scripting interface through which most of the API is accessed.</p>
|
||
<p><strong>Class Description:</strong><br />
|
||
Main toplevel type, provides access to most of the API though its members. An instance of LuaGameScript is available as the global object named <code>game</code>.</p>
|
||
<p><a href="https://lua-api.factorio.com/latest/LuaGameScript.html">View documentation</a></p>
|
||
<pre><code class="language-lua">LuaGameScript
|
||
</code></pre>
|
||
<hr />
|
||
<h1>getfenv</h1>
|
||
<p>Returns the current environment in use by the function. <code>f</code> can be a Lua function or a number that specifies the function at that stack level.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-getfenv">View documents</a></p>
|
||
<pre><code class="language-lua">function getfenv(f?: integer|fun(...any):...unknown)
|
||
-> table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>getmetatable</h1>
|
||
<p>If object does not have a metatable, returns nil. Otherwise, if the object's metatable has a __metatable field, returns the associated value. Otherwise, returns the metatable of the given object.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-getmetatable">View documents</a></p>
|
||
<pre><code class="language-lua">function getmetatable(object: any)
|
||
-> metatable: table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>global</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>global.__flib</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>global.__flib.dictionary</h1>
|
||
<pre><code class="language-lua">flib_dictionary_global
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">flib_dictionary_global
|
||
</code></pre>
|
||
<pre><code class="language-lua">flib_dictionary_global
|
||
</code></pre>
|
||
<hr />
|
||
<h1>global.__flib.on_tick_n</h1>
|
||
<pre><code class="language-lua">{ [number]: table<number, any> }
|
||
</code></pre>
|
||
<pre><code class="language-lua">{ [number]: table<number, any> }
|
||
</code></pre>
|
||
<hr />
|
||
<h1>global.__flib.translation</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>global.guis</h1>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>ipairs</h1>
|
||
<p>Returns three values (an iterator function, the table <code>t</code>, and <code>0</code>) so that the construction</p>
|
||
<pre><code class="language-lua"> for i,v in ipairs(t) do body end
|
||
</code></pre>
|
||
<p>will iterate over the key–value pairs <code>(1,t[1]), (2,t[2]), ...</code>, up to the first absent index.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-ipairs">View documents</a></p>
|
||
<pre><code class="language-lua">function ipairs(t: <T:table>)
|
||
-> fun(table: <V>[], i?: integer):integer, <V>
|
||
2. <T:table>
|
||
3. i: integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>load</h1>
|
||
<p>Loads a chunk.</p>
|
||
<p>If <code>chunk</code> is a string, the chunk is this string. If <code>chunk</code> is a function, <code>load</code> calls it repeatedly to get the chunk pieces. Each call to <code>chunk</code> must return a string that concatenates with previous results. A return of an empty string, <code>nil</code>, or no value signals the end of the chunk.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-load">View documents</a></p>
|
||
<pre><code class="language-lua">mode:
|
||
| "b" -- Only binary chunks.
|
||
| "t" -- Only text chunks.
|
||
-> "bt" -- Both binary and text.
|
||
</code></pre>
|
||
<pre><code class="language-lua">function load(chunk: string|function, chunkname?: string, mode?: "b"|"bt"|"t", env?: table)
|
||
-> function?
|
||
2. error_message: string?
|
||
</code></pre>
|
||
<hr />
|
||
<h1>loadfile</h1>
|
||
<p>Loads a chunk from file <code>filename</code> or from the standard input, if no file name is given.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-loadfile">View documents</a></p>
|
||
<pre><code class="language-lua">mode:
|
||
| "b" -- Only binary chunks.
|
||
| "t" -- Only text chunks.
|
||
-> "bt" -- Both binary and text.
|
||
</code></pre>
|
||
<pre><code class="language-lua">function loadfile(filename?: string, mode?: "b"|"bt"|"t", env?: table)
|
||
-> function?
|
||
2. error_message: string?
|
||
</code></pre>
|
||
<hr />
|
||
<h1>loadstring</h1>
|
||
<p>Loads a chunk from the given string.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-loadstring">View documents</a></p>
|
||
<pre><code class="language-lua">function loadstring(text: string, chunkname?: string)
|
||
-> function?
|
||
2. error_message: string?
|
||
</code></pre>
|
||
<hr />
|
||
<h1>localised_print</h1>
|
||
<p><code>localised_print()</code> allows printing <a href="https://lua-api.factorio.com/latest/concepts.html#LocalisedString">LocalisedString</a> to stdout without polluting the Factorio <a href="https://wiki.factorio.com/Log_file">log file</a>. This is primarily useful when communicating with external tools that launch Factorio as a child process.</p>
|
||
<p><a href="https://lua-api.factorio.com/latest/auxiliary/libraries.html#new-functions">View Documentation</a></p>
|
||
<pre><code class="language-lua">function localised_print(string: boolean|string|number|LuaObject|boolean|string|number|LuaObject|boolean|string|number|LuaObject|nil[]...(+1)[]...(+1))
|
||
</code></pre>
|
||
<hr />
|
||
<h1>log</h1>
|
||
<p><code>log()</code> can print <a href="https://lua-api.factorio.com/latest/concepts.html#LocalisedString">LocalisedStrings</a> to the Factorio <a href="https://wiki.factorio.com/Log_file">log file</a>. This, in combination with the serpent library, makes debugging in the data stage easier because it allows the inspection of entire prototype tables. For example, printing all properties of the sulfur item prototype can be done like so: <code>log(serpent.block(data.raw["item"]["sulfur"]))</code></p>
|
||
<p><a href="https://lua-api.factorio.com/latest/auxiliary/libraries.html#new-functions">View Documentation</a></p>
|
||
<pre><code class="language-lua">function _ENV.log(...any)
|
||
</code></pre>
|
||
<pre><code class="language-lua">function log(string: boolean|string|number|LuaObject|boolean|string|number|LuaObject|boolean|string|number|LuaObject|nil[]...(+1)[]...(+1))
|
||
</code></pre>
|
||
<pre><code class="language-lua">function _ENV.log(...any)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math</h1>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">factorio.mathlib
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.abs</h1>
|
||
<p>Returns the absolute value of <code>x</code>.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.abs%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.abs(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.acos</h1>
|
||
<p>Returns the arc cosine of <code>x</code> (in radians).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.acos%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.acos(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.asin</h1>
|
||
<p>Returns the arc sine of <code>x</code> (in radians).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.asin%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.asin(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.atan</h1>
|
||
<p>Returns the arc tangent of <code>x</code> (in radians).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.atan%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.atan(y: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.atan2</h1>
|
||
<p>Returns the arc tangent of <code>y/x</code> (in radians).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.atan2%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.atan2(y: number, x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.ceil</h1>
|
||
<p>Returns the smallest integral value larger than or equal to <code>x</code>.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.ceil%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.ceil(x: number)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.cos</h1>
|
||
<p>Returns the cosine of <code>x</code> (assumed to be in radians).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.cos%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.cos(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.cosh</h1>
|
||
<p>Returns the hyperbolic cosine of <code>x</code> (assumed to be in radians).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.cosh%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.cosh(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.deg</h1>
|
||
<p>Converts the angle <code>x</code> from radians to degrees.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.deg%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.deg(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.exp</h1>
|
||
<p>Returns the value <code>e^x</code> (where <code>e</code> is the base of natural logarithms).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.exp%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.exp(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.floor</h1>
|
||
<p>Returns the largest integral value smaller than or equal to <code>x</code>.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.floor%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.floor(x: number)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.fmod</h1>
|
||
<p>Returns the remainder of the division of <code>x</code> by <code>y</code> that rounds the quotient towards zero.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.fmod%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.fmod(x: number, y: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.frexp</h1>
|
||
<p>Decompose <code>x</code> into tails and exponents. Returns <code>m</code> and <code>e</code> such that <code>x = m * (2 ^ e)</code>, <code>e</code> is an integer and the absolute value of <code>m</code> is in the range [0.5, 1) (or zero when <code>x</code> is zero).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.frexp%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.frexp(x: number)
|
||
-> m: number
|
||
2. e: number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.ldexp</h1>
|
||
<p>Returns <code>m * (2 ^ e)</code> .</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.ldexp%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.ldexp(m: number, e: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.log</h1>
|
||
<p>Returns the logarithm of <code>x</code> in the given base.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.log%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.log(x: number, base?: integer)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.log10</h1>
|
||
<p>Returns the base-10 logarithm of x.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.log10%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.log10(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.max</h1>
|
||
<p>Returns the argument with the maximum value, according to the Lua operator <code><</code>.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.max%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.max(x: <Number:number>, ...<Number:number>)
|
||
-> <Number:number>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.min</h1>
|
||
<p>Returns the argument with the minimum value, according to the Lua operator <code><</code>.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.min%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.min(x: <Number:number>, ...<Number:number>)
|
||
-> <Number:number>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.modf</h1>
|
||
<p>Returns the integral part of <code>x</code> and the fractional part of <code>x</code>.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.modf%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.modf(x: number)
|
||
-> integer
|
||
2. number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.pow</h1>
|
||
<p>Returns <code>x ^ y</code> .</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.pow%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.pow(x: number, y: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.rad</h1>
|
||
<p>Converts the angle <code>x</code> from degrees to radians.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.rad%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.rad(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.random</h1>
|
||
<p><code>math.random()</code> is reimplemented within Factorio to be deterministic, both in the data stage and during runtime.</p>
|
||
<p>In the data stage, it is seeded with a constant number. During runtime, it uses the map's global random generator which is seeded with the map seed. The map's global random generator is shared between all mods and the core game, which all affect the random number that is generated. If this behaviour is not desired, <code>LuaRandomGenerator</code> can be used to create a random generator that is completely separate from the core game and other mods.</p>
|
||
<p>This method can't be used outside of events or during loading. Calling it with non-integer arguments will floor them instead of resulting in an error.</p>
|
||
<ul>
|
||
<li><code>math.random()</code>: Returns a float in the range [0,1).</li>
|
||
<li><code>math.random(n)</code>: Returns a integer in the range [1, n].</li>
|
||
<li><code>math.random(m, n)</code>: Returns a integer in the range [m, n].
|
||
See: <a href="">LuaRandomGenerator</a></li>
|
||
</ul>
|
||
<pre><code class="language-lua">function math.random(m: number, n: number)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.randomseed</h1>
|
||
<p>Using <code>math.randomseed()</code> in Factorio has no effect on the random generator, the function does nothing. If custom seeding or re-seeding is desired, <code>LuaRandomGenerator</code> can be used instead of <code>math.random()</code>.
|
||
See: <a href="">LuaRandomGenerator</a></p>
|
||
<pre><code class="language-lua">function math.randomseed(x: integer)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.sin</h1>
|
||
<p>Returns the sine of <code>x</code> (assumed to be in radians).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.sin%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.sin(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.sinh</h1>
|
||
<p>Returns the hyperbolic sine of <code>x</code> (assumed to be in radians).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.sinh%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.sinh(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.sqrt</h1>
|
||
<p>Returns the square root of <code>x</code>.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.sqrt%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.sqrt(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.tan</h1>
|
||
<p>Returns the tangent of <code>x</code> (assumed to be in radians).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.tan%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.tan(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.tanh</h1>
|
||
<p>Returns the hyperbolic tangent of <code>x</code> (assumed to be in radians).</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.tanh%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.tanh(x: number)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.tointeger</h1>
|
||
<p>If the value <code>x</code> is convertible to an integer, returns that integer.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.tointeger%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.tointeger(x: any)
|
||
-> integer?
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.type</h1>
|
||
<p>Returns <code>"integer"</code> if <code>x</code> is an integer, <code>"float"</code> if it is a float, or <code>nil</code> if <code>x</code> is not a number.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.type%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">return #1:
|
||
| "integer"
|
||
| "float"
|
||
| 'nil'
|
||
</code></pre>
|
||
<pre><code class="language-lua">function math.type(x: any)
|
||
-> "float"|"integer"|'nil'
|
||
</code></pre>
|
||
<hr />
|
||
<h1>math.ult</h1>
|
||
<p>Returns <code>true</code> if and only if <code>m</code> is below <code>n</code> when they are compared as unsigned integers.</p>
|
||
<p><a href="command:extension.lua.doc?%5B%22en-us/52/manual.html/pdf-math.ult%22%5D">View documents</a></p>
|
||
<pre><code class="language-lua">function math.ult(m: integer, n: integer)
|
||
-> boolean
|
||
</code></pre>
|
||
<hr />
|
||
<h1>mods</h1>
|
||
<p>See: <a href="">LuaBootstrap.active_mods</a></p>
|
||
<pre><code class="language-lua">{ [string]: string }
|
||
</code></pre>
|
||
<hr />
|
||
<h1>module</h1>
|
||
<p>Creates a module.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-module">View documents</a></p>
|
||
<pre><code class="language-lua">function module(name: string, ...any)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>newproxy</h1>
|
||
<pre><code class="language-lua">function newproxy(proxy: boolean|table|userdata)
|
||
-> userdata
|
||
</code></pre>
|
||
<hr />
|
||
<h1>next</h1>
|
||
<p>Allows a program to traverse all fields of a table. Its first argument is a table and its second argument is an index in this table. A call to <code>next</code> returns the next index of the table and its associated value. When called with <code>nil</code> as its second argument, <code>next</code> returns an initial index and its associated value. When called with the last index, or with <code>nil</code> in an empty table, <code>next</code> returns <code>nil</code>. If the second argument is absent, then it is interpreted as <code>nil</code>. In particular, you can use <code>next(t)</code> to check whether a table is empty.</p>
|
||
<p>The order in which the indices are enumerated is not specified, <em>even for numeric indices</em>. (To traverse a table in numerical order, use a numerical <code>for</code>.)</p>
|
||
<p>The behavior of <code>next</code> is undefined if, during the traversal, you assign any value to a non-existent field in the table. You may however modify existing fields. In particular, you may set existing fields to nil.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-next">View documents</a></p>
|
||
<pre><code class="language-lua">function next(table: table<<K>, <V>>, index?: <K>)
|
||
-> <K>?
|
||
2. <V>?
|
||
</code></pre>
|
||
<hr />
|
||
<h1>os.exit</h1>
|
||
<pre><code class="language-lua">function os.exit(...any)
|
||
</code></pre>
|
||
<pre><code class="language-lua">function os.exit(...any)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>package</h1>
|
||
<pre><code class="language-lua">factorio.packagelib
|
||
</code></pre>
|
||
<hr />
|
||
<h1>package.path</h1>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<pre><code class="language-lua">string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>pairs</h1>
|
||
<p>If <code>t</code> has a metamethod <code>__pairs</code>, calls it with t as argument and returns the first three results from the call.</p>
|
||
<p>Otherwise, returns three values: the <a href="http://www.lua.org/manual/5.2/manual.html#pdf-next">next</a> function, the table <code>t</code>, and <code>nil</code>, so that the construction</p>
|
||
<pre><code class="language-lua"> for k,v in pairs(t) do body end
|
||
</code></pre>
|
||
<p>will iterate over all key–value pairs of table <code>t</code>.</p>
|
||
<p>See function <a href="http://www.lua.org/manual/5.2/manual.html#pdf-next">next</a> for the caveats of modifying the table during its traversal.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-pairs">View documents</a></p>
|
||
<pre><code class="language-lua">function pairs(t: <T:table>)
|
||
-> fun(table: table<<K>, <V>>, index?: <K>):<K>, <V>
|
||
2. <T:table>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>pcall</h1>
|
||
<p>Calls the function <code>f</code> with the given arguments in <em>protected mode</em>. This means that any error inside <code>f</code> is not propagated; instead, <code>pcall</code> catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, <code>pcall</code> also returns all results from the call, after this first result. In case of any error, <code>pcall</code> returns <code>false</code> plus the error object.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-pcall">View documents</a></p>
|
||
<pre><code class="language-lua">function pcall(f: fun(...any):...unknown, arg1?: any, ...any)
|
||
-> success: boolean
|
||
2. result: any
|
||
3. ...any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>print</h1>
|
||
<p>Receives any number of arguments and prints their values to <code>stdout</code>, converting each argument to a string following the same rules of <a href="http://www.lua.org/manual/5.2/manual.html#pdf-tostring">tostring</a>.
|
||
The function print is not intended for formatted output, but only as a quick way to show a value, for instance for debugging. For complete control over the output, use <a href="http://www.lua.org/manual/5.2/manual.html#pdf-string.format">string.format</a> and <a href="http://www.lua.org/manual/5.2/manual.html#pdf-io.write">io.write</a>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-print">View documents</a></p>
|
||
<pre><code class="language-lua">function print(...any)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>rawequal</h1>
|
||
<p>Checks whether v1 is equal to v2, without invoking the <code>__eq</code> metamethod.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-rawequal">View documents</a></p>
|
||
<pre><code class="language-lua">function rawequal(v1: any, v2: any)
|
||
-> boolean
|
||
</code></pre>
|
||
<hr />
|
||
<h1>rawget</h1>
|
||
<p>Gets the real value of <code>table[index]</code>, without invoking the <code>__index</code> metamethod.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-rawget">View documents</a></p>
|
||
<pre><code class="language-lua">function rawget(table: table, index: any)
|
||
-> any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>rawlen</h1>
|
||
<p>Returns the length of the object <code>v</code>, without invoking the <code>__len</code> metamethod.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-rawlen">View documents</a></p>
|
||
<pre><code class="language-lua">function rawlen(v: string|table)
|
||
-> len: integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>rawset</h1>
|
||
<p>Sets the real value of <code>table[index]</code> to <code>value</code>, without using the <code>__newindex</code> metavalue. <code>table</code> must be a table, <code>index</code> any value different from <code>nil</code> and <code>NaN</code>, and <code>value</code> any Lua value.
|
||
This function returns <code>table</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-rawset">View documents</a></p>
|
||
<pre><code class="language-lua">function rawset(table: table, index: any, value: any)
|
||
-> table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>rcon</h1>
|
||
<p><strong>Global Description:</strong><br />
|
||
Allows printing messages to the calling RCON instance, if any.</p>
|
||
<p><strong>Class Description:</strong><br />
|
||
An interface to send messages to the calling RCON interface through the global object named <code>rcon</code>.</p>
|
||
<p><a href="https://lua-api.factorio.com/latest/LuaRCON.html">View documentation</a></p>
|
||
<pre><code class="language-lua">LuaRCON
|
||
</code></pre>
|
||
<hr />
|
||
<h1>remote</h1>
|
||
<p><strong>Global Description:</strong><br />
|
||
Allows registration and use of functions to communicate between mods.</p>
|
||
<p><strong>Class Description:</strong><br />
|
||
Registry of interfaces between scripts. An interface is simply a dictionary mapping names to functions. A script or mod can then register an interface with <a href="https://lua-api.factorio.com/latest/LuaRemote.html">LuaRemote</a>, after that any script can call the registered functions, provided it knows the interface name and the desired function name. An instance of LuaRemote is available through the global object named <code>remote</code>.</p>
|
||
<p><a href="https://lua-api.factorio.com/latest/LuaRemote.html">View documentation</a></p>
|
||
<h3>Example</h3>
|
||
<p>Will register a remote interface containing two functions. Later, it will call these functions through <code>remote</code>.</p>
|
||
<pre><code>remote.add_interface("human interactor",
|
||
{hello = function() game.player.print("Hi!") end,
|
||
bye = function(name) game.player.print("Bye " .. name) end})
|
||
-- Some time later, possibly in a different mod...
|
||
remote.call("human interactor", "hello")
|
||
remote.call("human interactor", "bye", "dear reader")
|
||
</code></pre>
|
||
<pre><code class="language-lua">LuaRemote
|
||
</code></pre>
|
||
<hr />
|
||
<h1>rendering</h1>
|
||
<p><strong>Global Description:</strong><br />
|
||
Allows rendering of geometric shapes, text and sprites in the game world.</p>
|
||
<p><strong>Class Description:</strong><br />
|
||
Allows rendering of geometric shapes, text and sprites in the game world through the global object named <code>rendering</code>. Each render object is identified by an id that is universally unique for the lifetime of a whole game.</p>
|
||
<p><strong>Note:</strong> If an entity target of an object is destroyed or changes surface, then the object is also destroyed.</p>
|
||
<p><a href="https://lua-api.factorio.com/latest/LuaRendering.html">View documentation</a></p>
|
||
<pre><code class="language-lua">LuaRendering
|
||
</code></pre>
|
||
<hr />
|
||
<h1>require</h1>
|
||
<p>Due to the changes to <code>package</code>, the functionality of <code>require()</code> changes. When using absolute paths, the path starts at the mod root. Additionally, <code>..</code> is disabled as a path variable. This means that it is not possible to load arbitrary files from outside the mod directory.</p>
|
||
<p>Factorio does however provide two ways to load files from other mods:</p>
|
||
<ul>
|
||
<li>The "lualib" directory of the core mod is included in the paths to be checked for files, so it is possible to require files directly from there, such as the "util" file by using <code>require("util")</code>.</li>
|
||
<li>Furthermore, it is possible to require files from other mods by using <code>require("__mod-name__.file")</code>.</li>
|
||
</ul>
|
||
<p><code>require()</code> can not be used in the console, in event listeners or during a <code>remote.call()</code>. The function expects any file to end with the <code>.lua</code> extension.</p>
|
||
<pre><code class="language-lua">function require(modname: string)
|
||
-> unknown
|
||
</code></pre>
|
||
<hr />
|
||
<h1>script</h1>
|
||
<p><strong>Global Description:</strong><br />
|
||
Provides an interface for registering game event handlers.</p>
|
||
<p><strong>Class Description:</strong><br />
|
||
Entry point for registering event handlers. It is accessible through the global object named <code>script</code>.</p>
|
||
<p><a href="https://lua-api.factorio.com/latest/LuaBootstrap.html">View documentation</a></p>
|
||
<pre><code class="language-lua">LuaBootstrap
|
||
</code></pre>
|
||
<hr />
|
||
<h1>select</h1>
|
||
<p>If <code>index</code> is a number, returns all arguments after argument number <code>index</code>; a negative number indexes from the end (<code>-1</code> is the last argument). Otherwise, <code>index</code> must be the string <code>"#"</code>, and <code>select</code> returns the total number of extra arguments it received.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-select">View documents</a></p>
|
||
<pre><code class="language-lua">index:
|
||
| "#"
|
||
</code></pre>
|
||
<pre><code class="language-lua">function select(index: integer|"#", ...any)
|
||
-> any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>serpent</h1>
|
||
<p>Lua serializer and pretty printer.<br />
|
||
Author: <a href="mailto:paul@kulchenko.com">Paul Kulchenko</a><br />
|
||
https://github.com/pkulchenko/serpent</p>
|
||
<pre><code class="language-lua">local serpent = require("serpent")
|
||
local a = {1, nil, 3, x=1, ['true'] = 2, [not true]=3}
|
||
a[a] = a -- self-reference with a table as key and value
|
||
|
||
print(serpent.dump(a)) -- full serialization
|
||
print(serpent.line(a)) -- single line, no self-ref section
|
||
print(serpent.block(a)) -- multi-line indented, no self-ref section
|
||
|
||
local fun, err = loadstring(serpent.dump(a))
|
||
if err then error(err) end
|
||
local copy = fun()
|
||
|
||
|
||
local ok, copy = serpent.load(serpent.dump(a))
|
||
print(ok and copy[3] == a[3])
|
||
</code></pre>
|
||
<p><br />
|
||
Note that line and block functions return pretty-printed data structures and if you want to deserialize them,
|
||
you need to add return before running them through loadstring. For example:</p>
|
||
<pre><code class="language-lua">loadstring('return '..require('mobdebug').line("foo"))() == "foo"
|
||
</code></pre>
|
||
<p><br />
|
||
If a table or a userdata value has <code>__tostring</code> or <code>__serialize</code> method, the method will be used to serialize the value.<br />
|
||
If <code>__serialize</code> method is present, it will be called with the value as a parameter. if <code>__serialize</code> method is not present, but <code>__tostring</code> is,
|
||
then tostring will be called with the value as a parameter. In both cases, the result will be serialized, so <code>__serialize</code> method can return a table,
|
||
that will be serialized and replace the original value.</p>
|
||
<p>Limitations:<br />
|
||
Doesn't handle userdata (except filehandles in io.* table).<br />
|
||
Threads, function upvalues/environments, and metatables are not serialized.</p>
|
||
<pre><code class="language-lua">serpent
|
||
</code></pre>
|
||
<hr />
|
||
<h1>serpent.block</h1>
|
||
<p>multi-line indented pretty printing, no self-ref section; sets indent, sortkeys, and comment options.</p>
|
||
<pre><code class="language-lua">function serpent.block(value: any, options?: serpent.options)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>serpent.dump</h1>
|
||
<p>Full serialization; sets name, compact and sparse options</p>
|
||
<pre><code class="language-lua">function serpent.dump(value: any, options?: serpent.options)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>serpent.line</h1>
|
||
<p>Single line pretty printing, no self-ref section; sets sortkeys and comment options;</p>
|
||
<pre><code class="language-lua">function serpent.line(value: any, options?: serpent.options)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>serpent.load</h1>
|
||
<p>loads serialized fragment; you need to pass {safe = false} as the second value if you want to turn safety checks off.<br />
|
||
Similar to pcall and loadstring calls, load returns status as the first value and the result or the error message as the second value.</p>
|
||
<pre><code class="language-lua">function serpent.load(str: string, options?: serpent.load_options)
|
||
-> boolean
|
||
2. any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>setfenv</h1>
|
||
<p>Sets the environment to be used by the given function.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-setfenv">View documents</a></p>
|
||
<pre><code class="language-lua">function setfenv(f: fun(...any):...integer|unknown, table: table)
|
||
-> function
|
||
</code></pre>
|
||
<hr />
|
||
<h1>setmetatable</h1>
|
||
<p>Sets the metatable for the given table. If <code>metatable</code> is <code>nil</code>, removes the metatable of the given table. If the original metatable has a <code>__metatable</code> field, raises an error.</p>
|
||
<p>This function returns <code>table</code>.</p>
|
||
<p>To change the metatable of other types from Lua code, you must use the debug library (<a href="http://www.lua.org/manual/5.2/manual.html#6.10">§6.10</a>).</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-setmetatable">View documents</a></p>
|
||
<pre><code class="language-lua">function setmetatable(table: table, metatable?: table|metatable)
|
||
-> table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>settings</h1>
|
||
<p><strong>Global Description:</strong><br />
|
||
Provides access to the current mod settings.</p>
|
||
<p><strong>Class Description:</strong><br />
|
||
Object containing mod settings of three distinct types: <code>startup</code>, <code>global</code>, and <code>player</code>. An instance of LuaSettings is available through the global object named <code>settings</code>.</p>
|
||
<p><a href="https://lua-api.factorio.com/latest/LuaSettings.html">View documentation</a></p>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<pre><code class="language-lua">LuaSettings
|
||
</code></pre>
|
||
<pre><code class="language-lua">table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string</h1>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string">View documents</a></p>
|
||
<pre><code class="language-lua">stringlib
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.byte</h1>
|
||
<p>Returns the internal numeric codes of the characters <code>s[i], s[i+1], ..., s[j]</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.byte">View documents</a></p>
|
||
<pre><code class="language-lua">function string.byte(s: string|number, i?: integer, j?: integer)
|
||
-> ...integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.char</h1>
|
||
<p>Returns a string with length equal to the number of arguments, in which each character has the internal numeric code equal to its corresponding argument.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.char">View documents</a></p>
|
||
<pre><code class="language-lua">function string.char(byte: integer, ...integer)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.dump</h1>
|
||
<p>Returns a string containing a binary representation (a <em>binary chunk</em>) of the given function.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.dump">View documents</a></p>
|
||
<pre><code class="language-lua">function string.dump(f: fun(...any):...unknown)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.find</h1>
|
||
<p>Looks for the first match of <code>pattern</code> (see <a href="http://www.lua.org/manual/5.2/manual.html#6.4.1">§6.4.1</a>) in the string.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.find">View documents</a></p>
|
||
<p>@<em>return</em> <code>start</code></p>
|
||
<p>@<em>return</em> <code>end</code></p>
|
||
<p>@<em>return</em> <code>...</code> — captured</p>
|
||
<pre><code class="language-lua">function string.find(s: string|number, pattern: string|number, init?: integer, plain?: boolean)
|
||
-> start: integer|nil
|
||
2. end: integer|nil
|
||
3. ...any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.format</h1>
|
||
<p>Returns a formatted version of its variable number of arguments following the description given in its first argument.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.format">View documents</a></p>
|
||
<pre><code class="language-lua">function string.format(s: string|number, ...any)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.gmatch</h1>
|
||
<p>Returns an iterator function that, each time it is called, returns the next captures from <code>pattern</code> (see <a href="http://www.lua.org/manual/5.2/manual.html#6.4.1">§6.4.1</a>) over the string s.</p>
|
||
<p>As an example, the following loop will iterate over all the words from string s, printing one per line:</p>
|
||
<pre><code class="language-lua"> s =
|
||
"hello world from Lua"
|
||
for w in string.gmatch(s, "%a+") do
|
||
print(w)
|
||
end
|
||
</code></pre>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.gmatch">View documents</a></p>
|
||
<pre><code class="language-lua">function string.gmatch(s: string|number, pattern: string|number)
|
||
-> fun():string, ...unknown
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.gsub</h1>
|
||
<p>Returns a copy of s in which all (or the first <code>n</code>, if given) occurrences of the <code>pattern</code> (see <a href="http://www.lua.org/manual/5.2/manual.html#6.4.1">§6.4.1</a>) have been replaced by a replacement string specified by <code>repl</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.gsub">View documents</a></p>
|
||
<pre><code class="language-lua">function string.gsub(s: string|number, pattern: string|number, repl: string|number|function|table, n?: integer)
|
||
-> string
|
||
2. count: integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.len</h1>
|
||
<p>Returns its length.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.len">View documents</a></p>
|
||
<pre><code class="language-lua">function string.len(s: string|number)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.lower</h1>
|
||
<p>Returns a copy of this string with all uppercase letters changed to lowercase.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.lower">View documents</a></p>
|
||
<pre><code class="language-lua">function string.lower(s: string|number)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.match</h1>
|
||
<p>Looks for the first match of <code>pattern</code> (see <a href="http://www.lua.org/manual/5.2/manual.html#6.4.1">§6.4.1</a>) in the string.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.match">View documents</a></p>
|
||
<pre><code class="language-lua">function string.match(s: string|number, pattern: string|number, init?: integer)
|
||
-> ...any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.pack</h1>
|
||
<p>Returns a binary string containing the values <code>v1</code>, <code>v2</code>, etc. packed (that is, serialized in binary form) according to the format string <code>fmt</code> (see <a href="http://www.lua.org/manual/5.2/manual.html#6.4.2">§6.4.2</a>) .</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.pack">View documents</a></p>
|
||
<pre><code class="language-lua">function string.pack(fmt: string, v1: string|number, v2?: string|number, ...string|number)
|
||
-> binary: string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.packsize</h1>
|
||
<p>Returns the size of a string resulting from <code>string.pack</code> with the given format string <code>fmt</code> (see <a href="http://www.lua.org/manual/5.2/manual.html#6.4.2">§6.4.2</a>) .</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.packsize">View documents</a></p>
|
||
<pre><code class="language-lua">function string.packsize(fmt: string)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.rep</h1>
|
||
<p>Returns a string that is the concatenation of <code>n</code> copies of the string <code>s</code> separated by the string <code>sep</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.rep">View documents</a></p>
|
||
<pre><code class="language-lua">function string.rep(s: string|number, n: integer, sep?: string|number)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.reverse</h1>
|
||
<p>Returns a string that is the string <code>s</code> reversed.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.reverse">View documents</a></p>
|
||
<pre><code class="language-lua">function string.reverse(s: string|number)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.sub</h1>
|
||
<p>Returns the substring of the string that starts at <code>i</code> and continues until <code>j</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.sub">View documents</a></p>
|
||
<pre><code class="language-lua">function string.sub(s: string|number, i: integer, j?: integer)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.unpack</h1>
|
||
<p>Returns the values packed in string according to the format string <code>fmt</code> (see <a href="http://www.lua.org/manual/5.2/manual.html#6.4.2">§6.4.2</a>) .</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.unpack">View documents</a></p>
|
||
<pre><code class="language-lua">function string.unpack(fmt: string, s: string, pos?: integer)
|
||
-> ...any
|
||
2. offset: integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>string.upper</h1>
|
||
<p>Returns a copy of this string with all lowercase letters changed to uppercase.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-string.upper">View documents</a></p>
|
||
<pre><code class="language-lua">function string.upper(s: string|number)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table</h1>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table">View documents</a></p>
|
||
<pre><code class="language-lua">tablelib
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.compare</h1>
|
||
<p>Compares a table for shallow equality</p>
|
||
<pre><code class="language-lua">function table.compare(tbl1: any, tbl2: any)
|
||
-> boolean
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.concat</h1>
|
||
<p>Given a list where all elements are strings or numbers, returns the string <code>list[i]..sep..list[i+1] ··· sep..list[j]</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table.concat">View documents</a></p>
|
||
<pre><code class="language-lua">function table.concat(list: table, sep?: string, i?: integer, j?: integer)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.deepcopy</h1>
|
||
<p>Deep copies a table</p>
|
||
<pre><code class="language-lua">function table.deepcopy(object: <T>)
|
||
-> <T>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.foreach</h1>
|
||
<p>Executes the given f over all elements of table. For each element, f is called with the index and respective value as arguments. If f returns a non-nil value, then the loop is broken, and this value is returned as the final value of foreach.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table.foreach">View documents</a></p>
|
||
<pre><code class="language-lua">function table.foreach(list: any, callback: fun(key: string, value: any):<T>|nil)
|
||
-> <T>|nil
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.foreachi</h1>
|
||
<p>Executes the given f over the numerical indices of table. For each index, f is called with the index and respective value as arguments. Indices are visited in sequential order, from 1 to n, where n is the size of the table. If f returns a non-nil value, then the loop is broken and this value is returned as the result of foreachi.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table.foreachi">View documents</a></p>
|
||
<pre><code class="language-lua">function table.foreachi(list: any, callback: fun(key: string, value: any):<T>|nil)
|
||
-> <T>|nil
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.getn</h1>
|
||
<p>Returns the number of elements in the table. This function is equivalent to <code>#list</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table.getn">View documents</a></p>
|
||
<pre><code class="language-lua">function table.getn(list: <T>[])
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.insert</h1>
|
||
<p>Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table.insert">View documents</a></p>
|
||
<pre><code class="language-lua">function table.insert(list: table, pos: integer, value: any)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.maxn</h1>
|
||
<p>Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table.maxn">View documents</a></p>
|
||
<pre><code class="language-lua">function table.maxn(table: table)
|
||
-> integer
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.move</h1>
|
||
<p>Moves elements from table <code>a1</code> to table <code>a2</code>.</p>
|
||
<pre><code class="language-lua">a2[t],··· =
|
||
a1[f],···,a1[e]
|
||
return a2
|
||
</code></pre>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table.move">View documents</a></p>
|
||
<pre><code class="language-lua">function table.move(a1: table, f: integer, e: integer, t: integer, a2?: table)
|
||
-> a2: table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.pack</h1>
|
||
<p>Returns a new table with all arguments stored into keys <code>1</code>, <code>2</code>, etc. and with a field <code>"n"</code> with the total number of arguments.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table.pack">View documents</a></p>
|
||
<pre><code class="language-lua">function table.pack(...any)
|
||
-> table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.remove</h1>
|
||
<p>Removes from <code>list</code> the element at position <code>pos</code>, returning the value of the removed element.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table.remove">View documents</a></p>
|
||
<pre><code class="language-lua">function table.remove(list: table, pos?: integer)
|
||
-> any
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.sort</h1>
|
||
<p>Sorts list elements in a given order, <em>in-place</em>, from <code>list[1]</code> to <code>list[#list]</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table.sort">View documents</a></p>
|
||
<pre><code class="language-lua">function table.sort(list: <T>[], comp?: fun(a: <T>, b: <T>):boolean)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table.unpack</h1>
|
||
<p>Returns the elements from the given list. This function is equivalent to</p>
|
||
<pre><code class="language-lua"> return list[i], list[i+1], ···, list[j]
|
||
</code></pre>
|
||
<p>By default, <code>i</code> is <code>1</code> and <code>j</code> is <code>#list</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-table.unpack">View documents</a></p>
|
||
<pre><code class="language-lua">function table.unpack(list: <T>[], i?: integer, j?: integer)
|
||
-> ...<T>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>table_size</h1>
|
||
<p>@<em>return</em> —</p>
|
||
<p>Factorio provides the <code>table_size()</code> function as a simple way to determine the size of tables with non-continuous keys, as the standard <code>#</code> operator does not work correctly for these. The function is a C++ implementation of the following Lua code, which is faster than doing the same in Lua:</p>
|
||
<pre><code>local function size(t)
|
||
local count = 0
|
||
for k,v in pairs(t) do
|
||
count = count + 1
|
||
end
|
||
return count
|
||
end
|
||
</code></pre>
|
||
<p>Note that <code>table_size()</code> does not work correctly for <a href="https://lua-api.factorio.com/latest/classes/LuaCustomTable.html">LuaCustomTable</a>, their size has to be determined with <a href="https://lua-api.factorio.com/latest/classes/LuaCustomTable.html#length_operator">LuaCustomTable::length_operator</a> instead.</p>
|
||
<p><a href="https://lua-api.factorio.com/latest/auxiliary/libraries.html#new-functions">View Documentation</a></p>
|
||
<pre><code class="language-lua">function _ENV.table_size(tbl: any)
|
||
-> unknown
|
||
</code></pre>
|
||
<pre><code class="language-lua">function table_size(table: table)
|
||
-> integer
|
||
</code></pre>
|
||
<pre><code class="language-lua">function _ENV.table_size(tbl: any)
|
||
-> unknown
|
||
</code></pre>
|
||
<hr />
|
||
<h1>testNames</h1>
|
||
<p>Run all test functions or tables provided as input.</p>
|
||
<pre><code> Input: a list of { name, instance }
|
||
instance can either be a function or a table containing test functions starting with the prefix "test"
|
||
|
||
return the number of failures and errors, 0 meaning success
|
||
</code></pre>
|
||
<p>parse the command-line arguments</p>
|
||
<pre><code class="language-lua">unknown
|
||
</code></pre>
|
||
<pre><code class="language-lua">unknown
|
||
</code></pre>
|
||
<pre><code class="language-lua">unknown
|
||
</code></pre>
|
||
<pre><code class="language-lua">unknown
|
||
</code></pre>
|
||
<hr />
|
||
<h1>tonumber</h1>
|
||
<p>When called with no <code>base</code>, <code>tonumber</code> tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then <code>tonumber</code> returns this number; otherwise, it returns <code>fail</code>.</p>
|
||
<p>The conversion of strings can result in integers or floats, according to the lexical conventions of Lua (see <a href="http://www.lua.org/manual/5.2/manual.html#3.1">§3.1</a>). The string may have leading and trailing spaces and a sign.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-tonumber">View documents</a></p>
|
||
<pre><code class="language-lua">function tonumber(e: any)
|
||
-> number?
|
||
</code></pre>
|
||
<hr />
|
||
<h1>tostring</h1>
|
||
<p>Receives a value of any type and converts it to a string in a human-readable format.</p>
|
||
<p>If the metatable of <code>v</code> has a <code>__tostring</code> field, then <code>tostring</code> calls the corresponding value with <code>v</code> as argument, and uses the result of the call as its result. Otherwise, if the metatable of <code>v</code> has a <code>__name</code> field with a string value, <code>tostring</code> may use that string in its final result.</p>
|
||
<p>For complete control of how numbers are converted, use <a href="http://www.lua.org/manual/5.2/manual.html#pdf-string.format">string.format</a>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-tostring">View documents</a></p>
|
||
<pre><code class="language-lua">function tostring(v: any)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>type</h1>
|
||
<p>Returns the type of its only argument, coded as a string. The possible results of this function are <code>"nil"</code> (a string, not the value <code>nil</code>), <code>"number"</code>, <code>"string"</code>, <code>"boolean"</code>, <code>"table"</code>, <code>"function"</code>, <code>"thread"</code>, and <code>"userdata"</code>.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-type">View documents</a></p>
|
||
<pre><code class="language-lua">type:
|
||
| "nil"
|
||
| "number"
|
||
| "string"
|
||
| "boolean"
|
||
| "table"
|
||
| "function"
|
||
| "thread"
|
||
| "userdata"
|
||
</code></pre>
|
||
<pre><code class="language-lua">function type(v: any)
|
||
-> type: "boolean"|"function"|"nil"|"number"|"string"...(+3)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>unpack</h1>
|
||
<p>Returns the elements from the given <code>list</code>. This function is equivalent to</p>
|
||
<pre><code class="language-lua"> return list[i], list[i+1], ···, list[j]
|
||
</code></pre>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-unpack">View documents</a></p>
|
||
<pre><code class="language-lua">function unpack(list: <T>[], i?: integer, j?: integer)
|
||
-> ...<T>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util</h1>
|
||
<pre><code class="language-lua">util
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.add_shift</h1>
|
||
<pre><code class="language-lua">function util.add_shift(a: Vector.1, b: Vector.1)
|
||
-> Vector.1
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.add_shift_offset</h1>
|
||
<pre><code class="language-lua">function util.add_shift_offset(offset_: Vector.1, table_: <T:table>)
|
||
-> <T:table>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.by_pixel</h1>
|
||
<pre><code class="language-lua">function util.by_pixel(x: number, y: number)
|
||
-> Vector.1
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.by_pixel_hr</h1>
|
||
<pre><code class="language-lua">function util.by_pixel_hr(x: number, y: number)
|
||
-> Vector.1
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.clamp</h1>
|
||
<pre><code class="language-lua">function util.clamp(x: <X:number>, lower: <Lower:number>, upper: <Upper:number>)
|
||
-> <Lower:number>|<Upper:number>|<X:number>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.color</h1>
|
||
<p>supports 'rrggbb', 'rgb', 'rrggbbaa', 'rgba', 'ww', 'w'</p>
|
||
<pre><code class="language-lua">function util.color(hex: string)
|
||
-> Color.0|Color.1
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.combine_icons</h1>
|
||
<p>This function takes 2 icons tables, and adds the second to the first, but applies scale,
|
||
shift and tint to the entire second set.<br />
|
||
This allows you to manipulate the entire second icons table in the same way as you would
|
||
manipulate a single icon when adding to the icons table.</p>
|
||
<pre><code class="language-lua">function util.combine_icons(icons1: table, icons2: table, inputs: { ["scale"]: number?, ["shift"]: Vector.1?, ["tint"]: (Color.0|Color.1)? }, default_icon_size: integer)
|
||
-> table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.conditional_return</h1>
|
||
<p>If both value and data are truthy, returns data, otherwise returns false</p>
|
||
<pre><code class="language-lua">return #1:
|
||
| false
|
||
</code></pre>
|
||
<pre><code class="language-lua">function util.conditional_return(value: any, data: <D:any>)
|
||
-> <D:any>|false
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.copy</h1>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.distance</h1>
|
||
<p>The distance between two MapPositions</p>
|
||
<pre><code class="language-lua">function util.distance(position1: MapPosition.0|MapPosition.1, position2: MapPosition.0|MapPosition.1)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.draw_as_glow</h1>
|
||
<pre><code class="language-lua">function util.draw_as_glow(layer: <L:table>)
|
||
-> <L:table>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.empty_sprite</h1>
|
||
<pre><code class="language-lua">function util.empty_sprite(animation_length: integer)
|
||
-> table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.foreach_sprite_definition</h1>
|
||
<pre><code class="language-lua">function util.foreach_sprite_definition(table_: <T:table>, fun_: fun(t: <T:table>))
|
||
-> <T:table>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.format_number</h1>
|
||
<pre><code class="language-lua">function util.format_number(amount: number, append_suffix: boolean)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.formattime</h1>
|
||
<pre><code class="language-lua">function util.formattime(ticks: integer)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.get_color_with_alpha</h1>
|
||
<pre><code class="language-lua">function util.get_color_with_alpha(color: Color.0|Color.1, alpha: number, normalized_alpha: boolean)
|
||
-> Color.0|Color.1
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.get_walkable_tile</h1>
|
||
<pre><code class="language-lua">function util.get_walkable_tile()
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.increment</h1>
|
||
<pre><code class="language-lua">function util.increment(t: { [<K:boolean|string|number|table>]: number }, k: <K:boolean|string|number|table>, v?: number)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.insert_safe</h1>
|
||
<pre><code class="language-lua">function util.insert_safe(entity?: LuaEntity, item_dict?: ItemStackDefinition)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.list_to_map</h1>
|
||
<pre><code class="language-lua">function util.list_to_map(list: any[])
|
||
-> { [any]: true }
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.merge</h1>
|
||
<p>Recursively merges and/or deep-copies tables.
|
||
Entries in later tables override entries in earlier ones, unless
|
||
both entries are themselves tables, in which case they are recursively merged.
|
||
Non-merged tables are deep-copied, so that the result is brand new.</p>
|
||
<pre><code class="language-lua">function util.merge(tables: table[])
|
||
-> table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.mix_color</h1>
|
||
<p>Mixes two colors together</p>
|
||
<pre><code class="language-lua">function util.mix_color(c1: Color.0|Color.1, c2: Color.0|Color.1)
|
||
-> Color.0|Color.1
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.moveposition</h1>
|
||
<pre><code class="language-lua">function util.moveposition(position: Vector.1, direction: defines.direction, distance: number)
|
||
-> Vector.1
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.mul_shift</h1>
|
||
<pre><code class="language-lua">function util.mul_shift(shift: <T:Vector.1>, scale: number)
|
||
-> <T:Vector.1>|Vector.1
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.multiply_color</h1>
|
||
<pre><code class="language-lua">function util.multiply_color(c1: Color.0|Color.1, n: number)
|
||
-> Color.0|Color.1
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.multiplystripes</h1>
|
||
<pre><code class="language-lua">function util.multiplystripes(count: integer, stripes: table)
|
||
-> table
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.online_players</h1>
|
||
<pre><code class="language-lua">function util.online_players()
|
||
-> LuaPlayer[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.oppositedirection</h1>
|
||
<pre><code class="language-lua">function util.oppositedirection(direction: defines.direction)
|
||
-> defines.direction
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.parse_energy</h1>
|
||
<pre><code class="language-lua">function util.parse_energy(energy: string)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.positiontostr</h1>
|
||
<pre><code class="language-lua">function util.positiontostr(pos: MapPosition.0|MapPosition.1)
|
||
-> string
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.premul_color</h1>
|
||
<p>Multiplies all color channels by alpha</p>
|
||
<pre><code class="language-lua">function util.premul_color(color: <T:Color.0|Color.1>)
|
||
-> <T:Color.0|Color.1>
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.product_amount</h1>
|
||
<pre><code class="language-lua">function util.product_amount(product: table)
|
||
-> number
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.remove_from_list</h1>
|
||
<p>Remove the first occurance of value from the array</p>
|
||
<pre><code class="language-lua">function util.remove_from_list(list: any[], value: any)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.remove_safe</h1>
|
||
<pre><code class="language-lua">function util.remove_safe(entity?: LuaEntity, item_dict?: ItemStackDefinition)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.remove_tile_references</h1>
|
||
<p>Does not handle:</p>
|
||
<ul>
|
||
<li>explicit tile filters in "selection-tool" items</li>
|
||
<li>ItemPrototype::place_as_tile</li>
|
||
<li>TilePrototype::next_direction</li>
|
||
<li>TilePrototype::transition_merges_with_tile</li>
|
||
<li>general tile transitions, only removes tile names from water_tile_type_names</li>
|
||
</ul>
|
||
<p>@<em>param</em> <code>data</code> — Seriously pass the global data</p>
|
||
<pre><code class="language-lua">function util.remove_tile_references(data: table, array_of_tiles_to_remove: string[])
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.split</h1>
|
||
<pre><code class="language-lua">function util.split(inputstr: string, sep: string)
|
||
-> string[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.split_whitespace</h1>
|
||
<pre><code class="language-lua">function util.split_whitespace(string: string)
|
||
-> string[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.string_starts_with</h1>
|
||
<pre><code class="language-lua">function util.string_starts_with(str: string, start: string)
|
||
-> boolean
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.table.compare</h1>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.table.deepcopy</h1>
|
||
<pre><code class="language-lua">function
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.technology_icon_constant_braking_force</h1>
|
||
<pre><code class="language-lua">function util.technology_icon_constant_braking_force(technology_icon: string)
|
||
-> table[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.technology_icon_constant_capacity</h1>
|
||
<pre><code class="language-lua">function util.technology_icon_constant_capacity(technology_icon: string)
|
||
-> table[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.technology_icon_constant_damage</h1>
|
||
<pre><code class="language-lua">function util.technology_icon_constant_damage(technology_icon: string)
|
||
-> table[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.technology_icon_constant_equipment</h1>
|
||
<pre><code class="language-lua">function util.technology_icon_constant_equipment(technology_icon: string)
|
||
-> table[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.technology_icon_constant_followers</h1>
|
||
<pre><code class="language-lua">function util.technology_icon_constant_followers(technology_icon: string)
|
||
-> table[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.technology_icon_constant_mining</h1>
|
||
<pre><code class="language-lua">function util.technology_icon_constant_mining(technology_icon: string)
|
||
-> table[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.technology_icon_constant_movement_speed</h1>
|
||
<pre><code class="language-lua">function util.technology_icon_constant_movement_speed(technology_icon: string)
|
||
-> table[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.technology_icon_constant_productivity</h1>
|
||
<pre><code class="language-lua">function util.technology_icon_constant_productivity(technology_icon: string)
|
||
-> table[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.technology_icon_constant_range</h1>
|
||
<pre><code class="language-lua">function util.technology_icon_constant_range(technology_icon: string)
|
||
-> table[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.technology_icon_constant_speed</h1>
|
||
<pre><code class="language-lua">function util.technology_icon_constant_speed(technology_icon: string)
|
||
-> table[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>util.technology_icon_constant_stack_size</h1>
|
||
<pre><code class="language-lua">function util.technology_icon_constant_stack_size(technology_icon: string)
|
||
-> table[]
|
||
</code></pre>
|
||
<hr />
|
||
<h1>warn</h1>
|
||
<p>Emits a warning with a message composed by the concatenation of all its arguments (which should be strings).</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-warn">View documents</a></p>
|
||
<pre><code class="language-lua">function warn(message: string, ...any)
|
||
</code></pre>
|
||
<hr />
|
||
<h1>xpcall</h1>
|
||
<p>Calls function <code>f</code> with the given arguments in protected mode with a new message handler.</p>
|
||
<p><a href="http://www.lua.org/manual/5.4/manual.html#pdf-xpcall">View documents</a></p>
|
||
<pre><code class="language-lua">function xpcall(f: fun(...any):...unknown, msgh: function, arg1?: any, ...any)
|
||
-> success: boolean
|
||
2. result: any
|
||
3. ...any
|
||
</code></pre>
|
||
</body>
|
||
</html>
|