Closed harrygallagher4 closed 2 years ago
I like the idea of putting a *module*
at the end of the file 🤔 I'll have a look at that! Sorry for the issue! I've run into it once I think then I just put a nil
at the end of the file which will also fix it. This bug is basically if your module ends with a table, if you put nil
or anything else it should be fine.
Wrapping the entire file in this macro (after the (require-macros ...)
that the compiler inserts) could be a solution. It should allow users to compile files that aren't aniseed modules while just appending *module*
to everything would break that. I had a little trouble modifying the compiler but I'll see if I can get something working and open a PR. The macro implementation might also need a few safety checks, let me know what you think.
(macro wrap-module [...]
(let [body# [...]
last-expr# (table.remove body#)]
(table.insert body#
`(let [original-return# (do ,last-expr#)]
(or ,(sym "*module*") original-return#)))
`(do ,(unpack body#))))
Hi, I've noticed this bug a couple times but I finally managed to figure out how to reliably recreate it. The way aniseed uses
package.loaded['module']
to set the value ofrequire('module')
seems to be unreliable. In cases where the compiled lua file has an actualreturn
statement at the end the returned value overrides the value set inpackage.loaded
.Here's a small example
This can be fixed by using an aniseed
def(n)(-)
at the end of the module or just putting*module*
after everything.This is most likely to cause issues when the last call in the module is a side-effecting function that happens to have a return value