include in lua

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

include in lua

Post by LuMo »

i read the following:
The require Function
i am not sure if it is what i am searching for...
i guess it executes the lua file as it is required.

what i am asking is it possible to use another lua file (same as in php, java or c/c++ by include?)
so that i can use functions from this file when i want?

greets
LuMo, who is totally new to lua
Benihana
Posts: 12
Joined: Sun Jul 31, 2005 4:54 am

Post by Benihana »

You have probably figured it out by now, but:

"...require does the same job as dofile, but with two important differences. First, require searches for the file in a path; second, require controls whether a file has already been run to avoid duplicating the work." - Programming in Lua

So basically use dofile unless you need to search for the file dynamically and you want to load the code several times.

Not sure why you would want to do this...I really would recommend sticking to one file. Do you have some Lua Libraries you are developing?
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

nah, i just write on one little game
but code grows when you get into details
code has now 1200 lines (with comments)

and i am used to have no files larger than max 500 lines
so i get lost in the huge amount...

greets
Benihana
Posts: 12
Joined: Sun Jul 31, 2005 4:54 am

Post by Benihana »

You can always use a comment line with asterisks across it, or some other deliniater. If I have reusable code I keep it seperate from the games code by doing such. Also, I HOPE you are using a Lua dev...there are a few out there. I use find a lot...would be nice to have a IDE with a little search box at the bottom like Firefox.
Post Reply