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

hi,

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

eg

setup.lua
[lua]initStuff()[/lua]

level1.lua
[lua]loadfile(“setup.lua”)
doStuff()[/lua]

level2.lua
[lua]loadfile(“setup.lua”)
doStuff()[/lua]

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 [import]uid: 6645 topic_id: 4364 reply_id: 304364[/import]

ie level1.lua is effectively

[lua]initStuff()
doStuff()[/lua]

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)
[import]uid: 6645 topic_id: 4364 reply_id: 13616[/import]

@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 :slight_smile: [import]uid: 7849 topic_id: 4364 reply_id: 13621[/import]

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

Carlos [import]uid: 24 topic_id: 4364 reply_id: 13676[/import]

ok thanks carlos

i can just restructure with a module

regards
j [import]uid: 6645 topic_id: 4364 reply_id: 13678[/import]

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 [import]uid: 12108 topic_id: 4364 reply_id: 14265[/import]

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 :slight_smile:

Logic??

chris
[import]uid: 4795 topic_id: 4364 reply_id: 82988[/import]

It’s for security reasons (apple’s point of view)
[import]uid: 84637 topic_id: 4364 reply_id: 82996[/import]

It’s for security reasons (apple’s point of view)
[import]uid: 84637 topic_id: 4364 reply_id: 82997[/import]