Forums » MacOS X

Help learning Lua

123»
Jun 02, 2006 Person link
I'm trying to teach myself to program in Lua, can anyone give me some starters to:
1) find documentation
2) download all the files I'll need to run Lua programs
3) download all programs I'll need to write Lua programs

Yeah, if anyone can help, that'll be great. As for #1, I'm ordering the Second Edition of Programming in Lua, but I don't know how much that'll help.

-Calder
Jun 03, 2006 ananzi link
if you want to learn programming use a language that has some standard libraries so you can actually do something .... ruby,python,vb.net

if you still want lua.... do you play world of warcraft... its interface is lua and xml. try playing with some interface mods, there are faqs all over the internet.

for raw lua, http://luaforge.net/frs/?group_id=110 , get http://luaforge.net/frs/download.php/1432/lua5_1_Darwin83_bin.tar.gz , unpack it, drill down to bin, darwin83 and do 'open with' on lua5.1 and choose applications/utilities/terminal.

you should see a prompt.

type in
print ("Hello World!")

-----------

then use google. for example

http://www.icculus.org/~theoddone33/lua/
----------

if u want to write a lua program into a file and run it, open up terminal and use unix commands to copy the lua files to /usr/bin and then copy /usr/bin/lua5.1 to /usr/bin/lua then you can run lua myfile.lua to run programs from terminal

Jun 03, 2006 roguelazer link
Woah. I agree with ananzi. Cue Wormwood.
Jun 05, 2006 Person link
Thanks ananzi but... uh... Darwin needs 10.3 right? Am I screwed?
plznoplznoplzno...

-Calder
Jun 05, 2006 Gavan link
No you're not screwed.
Jun 05, 2006 ananzi link
i dont know.

first off, you may have confused 'Darwin' with 'DarwinPorts'.

DarwinPorts requires 10.3 - DarwinPorts is a bunch of non-apple volunteers people who decided to port a bunch of unix crap to OSX.

Darwin, on the other hand, is the nickname of Apple's operating system OSX, including 10.0, 10.1, 10.2, etc etc etc. A lot of people who port stuff to OSX will call their build 'Darwin' for this reason.

As far as the lua binary, it will probably work because it does not rely on hardly any operating system services. but i dont have access to a 10.2 box so I cant be sure.

so, you have to try it yourself.

----

------- if the binary doesnt work -----------

----

if it doesnt work, you need to download the lua source code and compile it yourself.

that will definitely work.

i know this because all lua needs is a c compiler, and 10.2 is fully capable of running a c compiler.

-------

to find out if you have a c compiler, open a terminal and type 'gcc'. if it says command not found, you dont have it.

you get gcc by installing xcode.
this page:
http://fink.sourceforge.net/download/index.php?phpLang=en
will tell you which version of xcode to get. you download it from apple after registering as a developer.

after you do that, go to the lua download site, get the lua_5_1_sources.tar.gz, open a terminal, 'cd' to wherver you downloaded it (probably cd Desktop), make sure you removed the old binary version of lua if it didnt work, and then type this into a terminal...

tar -xvf lua5_1_sources.tar
cd lua5.1
make macosx
sudo make install

now try typing this at your terminal:

lua5.1

you should get something like this:

Lua 5.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio
>

otherwise, you probably dont have /usr/local/bin in your PATH.

----

to add /usr/local/bin to your PATH, do this:

find out which shell you are using. open a terminal and run 'ps'. hopefully it says 'bash'. if it says 'csh' or something, i dont know what to do. i give up.

if it says bash, add this command to the end of your ~/.bash_profile file

export PATH=$PATH:/usr/local/bin

or if you are too lazy to learn how to edit a text file, you can copy and paste this command into the terminal, which will add it for you:

echo "export PATH=\$PATH:/usr/local/bin" >> ~/.bash_profile

----

the end.
Jun 06, 2006 Person link
Thank you ananzi, you're a lifesaver. Or-a-nearly-botched-attempt-at-learning-lua saver. I've downloaded all the stuff and I'm waiting till my dad gets home so he can install it.

-Calder
Jun 06, 2006 Person link
Uh-oh, more problems here ananzi... sorry. Did you edit your post to exclude the fink part? Because I just installed fink, typed gcc and it still sais it doesn't know the command... Do I need XCode? And isn't that only for 10.3?

Thanks,
-Calder

[EDIT] I followed the rest of your steps anyway, and when I got to type 'make macosx' it said the make command was not found.
Jun 06, 2006 ananzi link
sorry, my original instructions were wrong. yes i did edit them.
i have only had a mac for 1 month so thats my excuse.

You do need xcode (or whatever they called the developer tools before they named it xcode)

You might have Xcode on your installation OSX CD/DVD. It might have an 'Xcode' installer icon, or 'mac osx developer tools', or whatever. Check that first.

If not, you can download a compiler for 10.2 from apple.com.

You have to go to http://connect.apple.com and get working with apple developer connection. You can use your Apple ID there, i think, i cant remember. You might have to register. But it is free.

After that, go back to http://connect.apple.com then 'log in'.

After that, click on 'downloads'. Then on the righthand side click 'Developer Tools', then go all the way at the bottom. There is a 300MB download from December 2002, its 'mac osx developer tools' for osx 10.2.

Install that, and you should now be able to type 'make' and 'gcc' at the prompt.

Jun 06, 2006 Person link
Ok ananzi, two more technical problem.

1) I can't install the gcc update 3.3 because I don't have 10.3. Is that going to be a big issue?

2) I get to the 'sudo make install' part and I type an administrator password. It doesn't work. Any idea what the SUPER user's password is, if it's not the administrator's?

-Calder

P.S. Once I get this working, (assuming I can) what do I use to edit and run Lua scripts?
Jun 06, 2006 roguelazer link
1) It shouldn't matter as long as the lua code is portable C.

2) For "sudo", you use your user account's password. The super-user's password (what you need to use "su") is usually the same as the password of the first administrator account created on the machine.

3/PS) You edit them in any text editor (vim > emacs) and you run them with the lua5.1 binary (which ought to be symlinked to lua) by typing lua5.1 /path/to/script.file
Jun 07, 2006 ananzi link
open up two terminals (in terminal, hit apple-n). in one terminal type 'nano hello.lua' , then type 'print("hello")', then hit control-o. in the other terminal type 'lua5.1 hello.lua'. you can rerun by hitting 'up arrow' then 'enter'. use apple-` to switch between terminals.

you can also use TextEdit. in TextEdit preferences, switch from 'rich text' to 'plain text', turn off 'check spelling as you type', and in open/save turn off 'add .txt extension'. To start TextEdit from the terminal, type 'open -e hello.lua'
Jun 07, 2006 Person link
ananzi and rogue, my dad and I can't remember for the life of us what the first administrator password was... Is there any way we could
a) figure it out
or
b) install lua without sudo
?

-_- sorry...

-Calder

[EDIT] I was browsing through hidden files for no reason whatsoever, and I found a locked folder called root. Does that have password stuff inside? If it does, I know a really easy trick to bypass all the fancy OSX security and get to it. mwuhahahaha...
/me loves firewire

[EDIT2] Ok, forget I asked. I figured out how to enable the root account and how to change the root password. Hopefully I'll be on my feet with Lua in no-time, thanks to youguys. Seriously, thanks a ton. And BTW, I always forget, ananzi, whether you take 'troll' as a compliment or not. From now on, I'll refer to you by your title of preference. :D
Jun 07, 2006 ananzi link
i dont know much about osx. i dont know what you mean by 'first administrator password'. is that root? like roguelazer said, you dont need the root password to use sudo, just your users password. if your username is bilbo and your password is zogby, when you type 'sudo' and it says 'Password:', then you type in zogby.

if you forget a users password, you can change it by logging in as root and typing 'passwd theusername'. also without trolls, civilization could not exist.
Jun 07, 2006 roguelazer link
lua really is a horrid language, though. Just fyi on that. I plan to encapsulate the UI's lua with as much ruby as is humanly possible as soon as possible. Eww. Lua.
Jun 08, 2006 Person link
Sorry ananzi, I've got another roadblock here. I changed the root password using NetInfo, but it still says wrong password every time I try to authenticate sudo.


If you look up, you'll see the second part of my problem. When I type 'make macosx' it gives an error on the third step that has something to do with installing 'all'. I can't make any sense of it...

-Calder
Jun 08, 2006 Person link
Does
Root/=Super User
?

/me is beginning to think so... :C

-Calder
Jun 08, 2006 Person link
Oh CRAP! I screwed up the sudoers file, :C
This won't be an easy fix.

-Calder
Jun 08, 2006 roguelazer link
root is the same as super-user.

When using 'sudo' use YOUR USER ACCOUNT'S PASSWORD!!!! NOTHING ELSE!!!

You should never edit the sudoers file on an OS X machine.

And the thing with make having nothing to do merely means that you already did the compile, and 'make' is smart enough to know that you don't need to recompile the stuff. You only need to do 'sudo make install'
Jun 08, 2006 ananzi link
If you know the root password, just do this. Type 'su', type in root password, then cd to the lua directory and then do 'make install' (no sudo required). BTW su is very different from sudo, they require different passwords.

As for sudo and your pasted image...

1. What is calderco's password? Did you type that in when you ran sudo? Like roguelazer said, when you use sudo don't type in the root password, type in calderco's password. If you dont know calderco's password, you can probably reset it by logging in as root, then typing 'passwd calderco'.

2. wow, NetInfo.. very interesting.. didnt know about this thing....

3. yes, root = superuser, which is a rough equivalent of 'Administrator' on windows.

4. to allow someone to sudo, go to system preferences/Accounts and click 'allow this user to administer the computer'. If 10.2.x doesnt have that feature, you can do the same thing in NetInfo Manager; basically you add 'calderco' to the 'admin' group. Go to 'groups' then 'admin', then click on the 'users' property in the bottom half of the window, to make that line blue. Now up at top screen, hit Directory, 'add value', then you can put calderco in there. Also do the same thing for 'staff' group. You might have to reboot after that, i dont know.

5. to fix your sudoers file, you can just copy a new one over.

heres my sudoers file, you can probably cut and paste to get 'back to normal', since the thing only has 2 lines that actually do anything (the ones that dont start with '#')
and im guessing since 10.2.x uses NetInfo it used the same or similar sudoers file.

# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

# Defaults specification

# Runas alias specification

# User privilege specification
root ALL=(ALL) ALL
%admin ALL=(ALL) ALL

# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL

# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL

# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now

# ps, you get a gold star for persistence.