开发者

How to import lua file to execute it?

I'm using Lua Mac 5.1.4 Compiler.

I'm trying to import lua file 开发者_Go百科and run it.

I tried using this code:

% lua hello.lua

But I'm getting this error: stdin:1: unexpected symbol near '%'

Am I doing something wrong? This is my first day using lua so be easy on me.

Thank you.


The problem is probably that you saw this verbatim text in a tutorial:

% lua hello.lua

The '%' at the beginning of the line is not something you are supposed to type into your terminal, but is rather a generic prompt indicator. Sometimes you might see it written as '$' instead:

$ lua hello.lua

In either case, the first character is not something you type, but rather is a typographical convention to suggest that what follows is to be typed at a prompt. Your actual prompt might look something like this:

mo@macbook$

So you would type lua hello.lua but your screen would look like this:

mo@macbook$ lua hello.lua

So, try just entering lua hello.lua and see what happens.

Note that the error message you got regarding stdin:1 is likely from your shell (e.g. bash), and not from Lua (which never even started running due to the malformed command in the shell).


The error stdin:1: unexpected symbol near '%' suggests that you typed in % lua hello.lua while in an interactive lua session (or you executed a script containing it). Now that's something that you should type in in the commandline window.

Instead try something like print'Hello World!'


Lua provides two ways to call a file. One is the loadfile() and the other is the dofile() commands. Try using dofile("hello.lua").That should work.If it doesn't type the absolute path...:)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜