[closed] loadfile or dofile support to load code "as is"

8 replies [Last post]
jmp909
User offline. Last seen 10 weeks 5 days ago. Offline
Joined: 14 May 2010

hi,

it would be useful to have a way of including the contents of another file into my lua script

eg

setup.lua

1
initStuff()

level1.lua

1
2
loadfile("setup.lua")
doStuff()

level2.lua

1
2
loadfile("setup.lua")
doStuff()

i wanted to try do this when amending the Ghosts project so all the duplicate code could just be moved into a couple of generic include files

thanks
j

Replies

jmp909
User offline. Last seen 10 weeks 5 days ago. Offline
Joined: 14 May 2010

ie level1.lua is effectively

1
2
initStuff()
doStuff()

variables defined local in setup.lua would actually be local to level1.lua (ie setup.lua isn't parsed directly, it's code is just included into level1.lua)

jonbeebe
User offline. Last seen 1 week 6 days ago. Offline
Joined: 26 Jul 2010

@jmp909: I also looked into this when creating the sample app. I plan on eventually expanding on the sample app, using different graphics and changing a lot of things up to create a fully-functional game. Once I find the best way to modularize that code I'll share it, hopefully you come up with a solution before me :-)

carlos m. icaza's picture
carlos m. icaza
User offline. Last seen 6 weeks 5 days ago. Offline
Alumni
Joined: 22 Jun 2009

loadfile and dofile are in effect disable to to restrictions on the Apple SDK Developer Agreement.

Carlos

jmp909
User offline. Last seen 10 weeks 5 days ago. Offline
Joined: 14 May 2010

ok thanks carlos

i can just restructure with a module

regards
j

jhocking
User offline. Last seen 8 weeks 5 days ago. Offline
Joined: 4 Dec 2010

Thanks to Lua's flexibility it's not particularly hard to modularize repetitious code. Here's an example I wrote with one approach to doing that:
http://developer.anscamobile.com/forum/2010/12/12/finding-objects-parent#comment-14209

guruk's picture
guruk
User offline. Last seen 2 days 1 hour ago. Offline
Joined: 9 Feb 2010

why does it have to be compiled while runtime???

Couldn't it be done, we as Devs just get that feature from Corona
and CORONA ... before creating our iOS/Android Code, does create
LUA Files that put that pieces together.

That would help us Devs to program even more effective and Apple
gets one piece of code :)

Logic??

chris

Danny's picture
Danny
User offline. Last seen 36 min 36 sec ago. Offline
Staff
Joined: 17 Aug 2011

It's for security reasons (apple's point of view)

Danny's picture
Danny
User offline. Last seen 36 min 36 sec ago. Offline
Staff
Joined: 17 Aug 2011

It's for security reasons (apple's point of view)

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.