Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit 85ed0a9

Browse files
committed
Update require syntax and add require guards
1 parent 422edba commit 85ed0a9

32 files changed

+144
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ creating Factorio mods.
1212
Download the latest release from the
1313
[mod portal](https://mods.factorio.com/mod/flib) unzip it, and put it in your
1414
mods directory. You can access libraries provided by flib with
15-
`require("__flib__/position")`, etc.
15+
`require("__flib__.position")`, etc.
1616

1717
Add the flib directory to your language server's library. We recommend
1818
installing the [Factorio modding

area.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if ... ~= "__flib__.area" then
2+
return require("__flib__.area")
3+
end
4+
15
--- @diagnostic disable
26
--- @deprecated Use `bounding-box` instead.
37
local flib_area = {}

bounding-box.lua

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
local position = require("__flib__/position")
1+
if ... ~= "__flib__.bounding-box" then
2+
return require("__flib__.bounding-box")
3+
end
4+
5+
local position = require("__flib__.position")
26

37
--- Utilities for manipulating bounding boxes. All functions support both the shorthand and explicit syntaxes for boxes
48
--- and positions, and will preserve the syntax that was passed in. Boxes are considered immutable; all functions will
59
--- return new boxes.
610
--- ```lua
7-
--- local flib_bounding_box = require("__flib__/bounding-box")
11+
--- local flib_bounding_box = require("__flib__.bounding-box")
812
--- ```
913
--- @class flib_bounding_box
1014
local flib_bounding_box = {}
@@ -64,8 +68,10 @@ end
6468
function flib_bounding_box.contains_position(box, pos)
6569
local box = flib_bounding_box.ensure_explicit(box)
6670
local pos = position.ensure_explicit(pos)
67-
return
68-
box.left_top.x <= pos.x and box.left_top.y <= pos.y and box.right_bottom.x >= pos.x and box.right_bottom.y >= pos.y
71+
return box.left_top.x <= pos.x
72+
and box.left_top.y <= pos.y
73+
and box.right_bottom.x >= pos.x
74+
and box.right_bottom.y >= pos.y
6975
end
7076

7177
--- Return the box in explicit form.
@@ -219,11 +225,10 @@ end
219225
function flib_bounding_box.intersects_box(box1, box2)
220226
local box1 = flib_bounding_box.ensure_explicit(box1)
221227
local box2 = flib_bounding_box.ensure_explicit(box2)
222-
return
223-
box1.left_top.x < box2.right_bottom.x
224-
and box2.left_top.x < box1.right_bottom.x
225-
and box1.left_top.y < box2.right_bottom.y
226-
and box2.left_top.y < box1.right_bottom.y
228+
return box1.left_top.x < box2.right_bottom.x
229+
and box2.left_top.x < box1.right_bottom.x
230+
and box1.left_top.y < box2.right_bottom.y
231+
and box2.left_top.y < box1.right_bottom.y
227232
end
228233

229234
--- Return a new box with the same dimensions, moved by the given delta.

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Date: ????
66
- Added `gui-templates` module for building various common and/or annoying GUI components, including technology slots.
77
- Added `technology` module with various runtime technology-related utilities.
88
- Added technology slot styles.
9+
- Added require guards to allow requiring flib modules with any syntax without breaking upvalues.
910
Bugfixes:
1011
- Fixed `data_util.get_energy_value` not accepting capital `K` as a unit suffix. (#59)
1112
---------------------------------------------------------------------------------------------------

data-util.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
if ... ~= "__flib__.data-util" then
2+
return require("__flib__.data-util")
3+
end
4+
15
--- Utilities for data stage prototype manipulation.
26
--- ```lua
3-
--- local flib_data_util = require("__flib__/data-util")
7+
--- local flib_data_util = require("__flib__.data-util")
48
--- ```
59
--- @class flib_data_util
610
local flib_data_util = {}

data.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
require("prototypes/sprite")
2-
require("prototypes/style")
3-
require("prototypes/technology-slot-style")
1+
require("prototypes.sprite")
2+
require("prototypes.style")
3+
require("prototypes.technology-slot-style")

dictionary-lite.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
local gui = require("__flib__/gui-lite")
2-
local mod_gui = require("__core__/lualib/mod-gui")
3-
local table = require("__flib__/table")
1+
if ... ~= "__flib__.dictionary-lite" then
2+
return require("__flib__.dictionary-lite")
3+
end
4+
5+
local gui = require("__flib__.gui-lite")
6+
local mod_gui = require("__core__.lualib.mod-gui")
7+
local table = require("__flib__.table")
48

59
--- @class FlibDictionaryGlobal
610
--- @field init_ran boolean
@@ -25,7 +29,7 @@ local table = require("__flib__/table")
2529

2630
--- Utilities for creating dictionaries of localised string translations.
2731
--- ```lua
28-
--- local flib_dictionary = require("__flib__/dictionary-lite")
32+
--- local flib_dictionary = require("__flib__.dictionary-lite")
2933
--- ```
3034
--- @class flib_dictionary
3135
local flib_dictionary = {}

dictionary.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
local gui = require("__flib__/gui-lite")
2-
local mod_gui = require("__core__/lualib/mod-gui")
3-
local table = require("__flib__/table")
1+
if ... ~= "__flib__.dictionary" then
2+
return require("__flib__.dictionary")
3+
end
4+
5+
local gui = require("__flib__.gui-lite")
6+
local mod_gui = require("__core__.lualib.mod-gui")
7+
local table = require("__flib__.table")
48

59
--- @diagnostic disable
610
--- @deprecated Use 'dictionary-lite' instead.

direction.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
local flib_math = require("__flib__/math")
1+
if ... ~= "__flib__.direction" then
2+
return require("__flib__.direction")
3+
end
4+
5+
local flib_math = require("__flib__.math")
26

37
--- Functions for working with directions.
48
--- ```lua
5-
--- local flib_direction = require("__flib__/direction")
9+
--- local flib_direction = require("__flib__.direction")
610
--- ```
711
--- @class flib_direction
812
local flib_direction = {}

event.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if ... ~= "__flib__.event" then
2+
return require("__flib__.event")
3+
end
4+
15
--- @diagnostic disable
26
--- @deprecated use `script` directly
37
local flib_event = {}

0 commit comments

Comments
 (0)