Subdirectories - again

Hi Team,

what happened to the sub directory support? Any plans?

e.g.

1
2
3
4
5
6
7
8
9
10
images/main/anim{1..100}.png
images/main/background.png
images/screen2/background.png
lib/main/anim.lua
stages/screen2/main.lua
...
 
require "lib/main/anim"
reqiure "stages/screen2/main"
...

oh - with images it should work by specifying a baseDirectory:

display.newImage( filename [, baseDirectory] [, left, top] )
Returns an image object. It loads the image data from filename and by default looks in the
system.ResourceDirectory for that !le. If you specify the argument baseDirectory it
will look in that directory instead (see system.pathForFile for valid values of
baseDirectory).

hmm. does not work:

local rpath = (system.pathForFile("Icon.png",system.ResourceDirectory));
rpath = string.sub(rpath,1,string.len(rpath)-8).."images/test/";
local image = display.newImage("test.png",rpath);

it would be nice to be able to organize source code within subdirectories as well...

+1 for ability to organize lua files into subdirectories. My project is becoming pretty large, and it's annoying to have everything in a single directory...

On a closely related matter:

A library directory which the build process will scan for any require directives not supplied in the local folder.

Probably like most other users, I'm continuously adding reusable library files. But they have to be copied into current projects, and any tweaks have to be manually propagated to the source. It can get messy.

The principle of search paths is, of course, common in many development environments, and would be a big productivity boost for Corona.

I support too!

I read through Programming in Lua and had hoped that I could use the LUA_PATH global variable to define where the require function is to find the different directories, but it seems to have no effect! :(

The Corona doc on Advanced Programming techniques implies that one can modify the package.loaders array to modify where require function looks (and unlike Programming in Lua makes no reference to the LUA_PATH variable).

I'm going to have a play around with adding new functions to the package.loaders for now, but would love to see either better documentation on that or some other support of subdirectories!

I must have 20 lua files at the moment and it's just getting a bit painful, especially as I come from a Java background where you just bung classes into packages at whim.

+1 For lua files in subfolders!

One way to achive this is to automatically change require('sub/module') to require ('sub_module') and renaming the file on the file. Currently that is a solution that works so far, but you need to do this on your own.

+1, this is painful to have 50 billion files in 1 folder. I changed all my packages from:

require "enemies/Enemy"

to:

require "enemies.Enemy"

But it's still bleh....

Additionally, this makes it harder for me to share libraries with others; I have to ensure a unique name and ensure my code doesn't depend on filename(s). It's easier to just give them a uniquely named folder, or true reverse domain name, and call it a day.

views:2175 update:2011/9/17 18:17:57
corona forums © 2003-2011