This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do | |
local match = string.match | |
local cashedShortHEX = {["0"] = 0, ["1"] = 17, ["2"] = 34, ["3"] = 51, ["4"] = 68, ["5"] = 85, ["6"] = 102, ["7"] = 119, ["8"] = 136, ["9"] = 153, A = 170, B = 187, C = 204, E = 238, F = 255, a = 170, b = 187, c = 204, f = 255} | |
-- Converts HEX code to numbers in RGB | |
---@param hex string | |
---@return number red, number green, number blue | |
function hex2rgb(hex) | |
local length = #hex | |
if length == 7 then | |
local r, g, b = match(hex, '.(..)(..)(..)') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do | |
local floor = math.floor | |
---@param tbl any[] | |
---@param value any | |
---@param iStart integer? | |
---@param iEnd integer? | |
---@param reversed boolean? | |
---@return any? | |
function binSearch(tbl, value, iStart, iEnd, reversed) | |
-- Initialise numbers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### Compile *.lua2p files to *.lua files and format them | |
### https://github.com/ReFreezed/LuaPreprocess | |
use_cmd=0 | |
case "$OSTYPE" in | |
win32|cygwin|msys) use_cmd=1 ;; | |
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
push: | |
branches: | |
- main | |
name: Lint | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This file is the config file for the tool named Luacheck | |
-- Documentation: https://luacheck.readthedocs.io/en/stable/index.html | |
-- Ignore unused function and loop arguments | |
unused_args = false | |
-- Allow self defined globals | |
allow_defined = true | |
-- Ignore this functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# game.players vs game.get_player | |
/measured-command for 1, 100 do local p = game.players[game.player.index] end | |
/measured-command for 1, 100 do local p = game.get_player(game.player.index) end | |
# Strings as key in tables vs comparing strings | |
/c SUBSPACE_ENTITIES_FOR_BUILT = { | |
["subspace-item-injector"] = true, | |
["subspace-item-extractor"] = true, | |
["subspace-fluid-injector"] = true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This is just an example file | |
-- interacting with https://lua-api.factorio.com/latest/LuaCommandProcessor.html#LuaCommandProcessor.add_command | |
local function attach_commands(module) | |
for key, command in pairs(module.commands) do | |
local name = command.name or key | |
local description = command.description or {"special-command-description"} | |
commands.add_command(name, description, command.func) | |
-- maybe even other actions... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This is just an example file for some case of LuaRemote | |
if remote.interfaces["another-interface"] then | |
-- You can just check via script.active_mods["mod_name"] instead if it's 100% compatible | |
-- but if it's an interface from scenario you can do it | |
-- And look at https://lua-api.factorio.com/1.1.30/LuaBootstrap.html#LuaBootstrap.level it may help in such rare cases | |
require "my-another-file" | |
end | |
-- Also, don't use remote.call here, it won't work |