Trouble getting started with Lua

Posted by BishopOsiris on Sat 26 Nov 2016 02:35 PM — 8 posts, 34,241 views.

USA #0
I bought the book "Programming in Lua" fourth edition by Lerusalimschy. I downloaded a binary interpreter for Window x86 from http://luadist.org/. When I open it, it says its a compiler. I can't even get the very first program (hello world) to work. It just says "nil". I was really excited to get started with this language but I hit this road block right out of the gate :(

Is there is a difference between a compiler and an interpreter?

What am I doing wrong?
USA Global Moderator #1
Quote:
I can't even get the very first program (hello world) to work. It just says "nil".
You've failed to tell us what you did so we have no comments on why it didn't work.
Australia Forum Administrator #2
You can use the Immediate window inside MUSHclient (Ctrl+I) to try a lot of Lua stuff. A possible problem is that if you go into an infinite loop you will have to force-quit MUSHclient. You can add this timer to pretty-much prevent that:


<timers>
  <timer name="runaway" 
    enabled="y" 
    second="5.00" 
    send_to="12"
    active_closed="y" >
  <send>

runaway_instruction_limit = 100000

function hook ()
  debug.sethook (hook, "", runaway_instruction_limit)
  error ("Runaway instruction limit reached")
end -- hook

debug.sethook (hook, "", runaway_instruction_limit)

</send>

  </timer>
</timers>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.





As for your issue, copy/paste exactly what you tried, that printed "nil".
USA #3
How do I post images?
USA Global Moderator #4
Post them on an image sharing service and put the URL here.
Australia Forum Administrator #5
Why do you want to post an image? Copy and paste the code you were using, and copy and paste the error message you got.

Template:codetag
To make your code more readable please use [code] tags as described here.
USA #6
At the Lua prompt in my interpreter:

Lua>


I type:

Quote:
hello.lua


This is what it spits out:


stdin:1 attempt to index a nil value (global 'hello')
stack traceback:
     stdin:1: in main chunk
     [C]: in ?


The hello.lua file is in the same directory as the interpreter and it consists of this:

 print("hello world")
Amended on Wed 07 Dec 2016 08:53 PM by BishopOsiris
Australia Forum Administrator #7
If you want to run an external file, then run Lua with an argument, eg.


lua hello.lua


You don't start Lua up, and then type in a file name like you did.

However if you have already started the Lua interpreter up, then you can "dofile" it, eg. from inside Lua:


Lua>  dofile "test.lua"