Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use lua's load function #434

Open
sucrecacao opened this issue Jan 25, 2021 · 6 comments
Open

How to use lua's load function #434

sucrecacao opened this issue Jan 25, 2021 · 6 comments

Comments

@sucrecacao
Copy link

Hi,

How can I use lua's load function in moonscript ?
And does it work with a moonscript string only with lua string?

I have found related issue on this topic but it didn't help me solve the problem, maybe their meant to work with older moonscript version.

@daelvn
Copy link

daelvn commented Jan 25, 2021

load only works with Lua strings. If you want to load MoonScript strings, you have to use MoonScript's own function.

moonscript = require "moonscript.base"
lua_code   = moonscript.load "code!"

It's all detailed in the reference manual.

@sucrecacao
Copy link
Author

This doesn't work:
I got the following error:

lua: main.lua:1: module 'moonscript.base' not found:
        no field package.preload['moonscript.base']
        no file '/usr/local/share/lua/5.3/moonscript/base.lua'
        no file '/usr/local/share/lua/5.3/moonscript/base/init.lua'
        no file '/usr/local/lib/lua/5.3/moonscript/base.lua'
        no file '/usr/local/lib/lua/5.3/moonscript/base/init.lua'
        no file './moonscript/base.lua'
        no file './moonscript/base/init.lua'
        no file '/usr/local/lib/lua/5.3/moonscript/base.so'
        no file '/usr/local/lib/lua/5.3/loadall.so'
        no file './moonscript/base.so'
        no file '/usr/local/lib/lua/5.3/moonscript.so'
        no file '/usr/local/lib/lua/5.3/loadall.so'
        no file './moonscript.so'
stack traceback:
        [C]: in function 'require'
        main.lua:1: in main chunk
        [C]: in ?

But I installed moonscript through lua rocks and the library is located in:

~/.luarocks/share/lua/5.1/moonscript/base.lua

is there a way to solve this issue in a "clean" way? ( without messing with symlink)

@qaisjp
Copy link
Contributor

qaisjp commented Jan 25, 2021

According to https://stackoverflow.com/a/47267672/1517394 you might need to add eval $(luarocks path --bin) to your bashrc.

@sucrecacao
Copy link
Author

Ok I have advanced one step, I still get:

Built main.moon
lua: error loading module 'lpeg' from file '/home/joe/.luarocks/lib/lua/5.1/lpeg.so':
        /home/joe/.luarocks/lib/lua/5.1/lpeg.so: undefined symbol: lua_tointeger
stack traceback:
        [C]: in ?
        [C]: in function 'require'
        /home/joe/.luarocks/share/lua/5.1/moonscript/errors.lua:2: in main chunk
        [C]: in function 'require'
        ...rocks/share/lua/5.1/moonscript/transform/destructure.lua:13: in main chunk
        [C]: in function 'require'
        ...uarocks/share/lua/5.1/moonscript/transform/statement.lua:18: in main chunk
        [C]: in function 'require'
        /home/joe/.luarocks/share/lua/5.1/moonscript/transform.lua:2: in main chunk
        [C]: in function 'require'
        /home/joe/.luarocks/share/lua/5.1/moonscript/compile.lua:3: in main chunk
        [C]: in function 'require'
        /home/joe/.luarocks/share/lua/5.1/moonscript/base.lua:1: in main chunk
        [C]: in function 'require'
        main.lua:1: in main chunk
        [C]: in ?

Apparently lua has change the lua_tointeger function from 5.1 to 5.2, this might be the causes of the bug.
I have upgraded from lua5.1 to lua5.3, but I still have the error message.

@sucrecacao
Copy link
Author

Ok I have solved the issue using lua5.1 instead of lua which was using version 5.3

Does moon-script only work with 5.1?

@sucrecacao
Copy link
Author

sucrecacao commented Jan 25, 2021

I also had to use loadstring instead of load ( moonscript.loadstring)

Also to use lua load I had to use the old loadstring, so I guess my moonscript is just installed on 5.1 but most of the doc and issue are for 5.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants