Getting a project to work with moonscript 0.5.0-1
Posted: Sun May 20, 2018 1:48 pm
Anyone here know how to use moonscript with love? I have trouble getting a simple moonscript project to work.
I've attached a zip file with two identical versions of example code: one is written in plain Lua, the other written in moonscript with a main.lua file that is supposed to bootstrap the moonscript project. The Lua project works as expected and prints 'hello' on the screen, the moonscript version does not.
Moonscript stuff works fine when compiled with moonc, but I'm tired of the cumbersome debugging process and want to be able to run the moon files directly. It immediately fails however at the require('game') line, complaining that it can't find the module. According to the documentation, the package loader should be able to recognize and load .moon files after moonscript is required:
I tried adding this to the bootstrapper:
But:
...it says 'no file ./game.moon'
I also tried running it with moon instead of love, but then it doesn't find the required module:
So I tried the package hack in game.moon. That makes it find the module, but it still seems to try to run it as plain Lua:
What am I doing wrong?
Edit: it just occured to me that even if the moon files are recognized correctly, it may fail because it doesn't know about the package loader that love installs. Is it even possible to run uncompiled moonscript files with love?
I've attached a zip file with two identical versions of example code: one is written in plain Lua, the other written in moonscript with a main.lua file that is supposed to bootstrap the moonscript project. The Lua project works as expected and prints 'hello' on the screen, the moonscript version does not.
Moonscript stuff works fine when compiled with moonc, but I'm tired of the cumbersome debugging process and want to be able to run the moon files directly. It immediately fails however at the require('game') line, complaining that it can't find the module. According to the documentation, the package loader should be able to recognize and load .moon files after moonscript is required:
That doesn't seem to work at all:After moonscript is required, Lua’s package loader is updated to search for .moon files on any subsequent calls to require. [...] Any search paths in package.path ending in .lua are copied, rewritten to end in .moon, and then inserted in package.moonpath.
Code: Select all
$ love11 .
Error: main.lua:2: module 'game' not found:
no field package.preload['game']
no 'game' in LOVE game directories.
no file 'game' in LOVE paths.
no file './game.lua'
no file '/usr/share/luajit-2.0.5/game.lua'
no file '/usr/local/share/lua/5.1/game.lua'
no file '/usr/local/share/lua/5.1/game/init.lua'
no file '/usr/share/lua/5.1/game.lua'
no file '/usr/share/lua/5.1/game/init.lua'
no file './game.so'
no file '/usr/local/lib/lua/5.1/game.so'
no file '/usr/lib/lua/5.1/game.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
Code: Select all
package.path = package.path .. ";./?.moon;./?/init.moon"
Code: Select all
$ love11 .
Error: main.lua:3: module 'game' not found:
no field package.preload['game']
no 'game' in LOVE game directories.
no file 'game' in LOVE paths.
no file './game.lua'
no file '/usr/share/luajit-2.0.5/game.lua'
no file '/usr/local/share/lua/5.1/game.lua'
no file '/usr/local/share/lua/5.1/game/init.lua'
no file '/usr/share/lua/5.1/game.lua'
no file '/usr/share/lua/5.1/game/init.lua'
no file './game.moon'
no file './game/init.moon'
no file './game.so'
no file '/usr/local/lib/lua/5.1/game.so'
no file '/usr/lib/lua/5.1/game.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
I also tried running it with moon instead of love, but then it doesn't find the required module:
Code: Select all
$ moon game.moon
moon: game.moon:1: (1) module 'module' not found:No LuaRocks module found for module
no field package.preload['module']
no file '/root/.luarocks/share/lua/5.1/module.lua'
no file '/root/.luarocks/share/lua/5.1/module/init.lua'
no file '/usr/local/share/lua/5.1/module.lua'
no file '/usr/local/share/lua/5.1/module/init.lua'
no file './module.lua'
no file '/usr/local/lib/lua/5.1/module.lua'
no file '/usr/local/lib/lua/5.1/module/init.lua'
no file '/usr/share/lua/5.1/module.lua'
no file '/usr/share/lua/5.1/module/init.lua'
no file '/home/grump/.luarocks/share/lua/5.1/module.lua'
no file '/home/grump/.luarocks/share/lua/5.1/module/init.lua'
no file '/root/.luarocks/lib/lua/5.1/module.so'
no file '/usr/local/lib/lua/5.1/module.so'
no file './module.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.1/module.so'
no file '/usr/lib/lua/5.1/module.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file '/home/grump/.luarocks/lib/lua/5.1/module.so'
Code: Select all
$ moon game.moon
moon: error loading module 'module' from file './module/init.moon':
./module/init.moon:1: '=' expected near 'fn'
Edit: it just occured to me that even if the moon files are recognized correctly, it may fail because it doesn't know about the package loader that love installs. Is it even possible to run uncompiled moonscript files with love?