Skip to content

Commit c14926c

Browse files
committed
Fix the module define logic, handles missing base and numbers in the loaded module
I think Lua internals return a number sometimes which breaks all sorts, so we want to ignore nil and numbers, everything else is fair game (like tables, functions and strings)
1 parent 2147163 commit c14926c

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

fnl/nfnl/module.fnl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
The base value defaults to {}, an empty table."
5959

6060
(let [loaded (. package.loaded mod-name)]
61-
(if (and (= (type loaded) (type base))
62-
(not= nil loaded))
61+
(if (and (or (= (type loaded) (type base)) (= nil base))
62+
(and (not= nil loaded) (not= :number (type loaded))))
6363
loaded
6464
(or base {}))))
6565

fnl/spec/nfnl/module_spec.fnl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
(fn []
1818
(it "returns the loaded module if it's the same type as the base"
1919
(fn []
20+
(local m1 (define :nfnl.module))
21+
(assert.equals define m1.define)
22+
2023
(local m2 (define :nfnl.module {}))
2124
(assert.equals define m2.define)
2225

lua/nfnl/module.lua

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/spec/nfnl/module_spec.lua

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)