require and modules

0 views
Skip to first unread message

Ron Jeffries

unread,
Feb 22, 2011, 6:05:09 PM2/22/11
to iLuaBox
My next plan with the bowling demo was to modularize the code,
ultimately into the little testing framework, the bowling game, the
tests, and so on.

i followed the approach in Programming in Lua, which was to use the
"require" capability to set up a module. It appears that that's not
implemented in iLua? Or, if it is, can someone paste a couple of short
files to serve as examples?

I wound up using dofile, as is done between guidemo and gui, with all
my test framework functions global. I can see how I could make a
global table Assert or something, and hide them inside, calling with
Assert.beginTests() and so on.

Is that roughly the right approach to building more modular code with
iLua?

Thanks!

Ron

Tom Skwara

unread,
Feb 22, 2011, 6:54:19 PM2/22/11
to ilu...@googlegroups.com
Given that Apple restricts the use of dynamically loaded libraries, the 'require' function is not implemented in iLuaBox.  In fact, the entire 'package' library is not implemented (as stated in iLuaBox documentation).

Your approach to encapsulation should work fine, although you may want to avoid using the table name 'Assert' (assert is a Lua function name in the basic library).

Tom Skwara
MobileApp Systems



Ron Jeffries

unread,
Feb 22, 2011, 9:19:25 PM2/22/11
to iLuaBox
Ok, super, glad I didn't miss anything. Good point on assert.

Is there some inherent diff between what docile does and the require
stuff? Almost seems I could build require if I wanted to?

And good point on the Assert name.

Thanks,

Tom Skwara

unread,
Feb 24, 2011, 4:08:36 PM2/24/11
to ilu...@googlegroups.com
The 'require' function does roughly the same job as 'dofile'.  The two differences are that 'require' will search for a file in a path (directories not yet implemented in iLuaBox), and second, the file will not load again if it is already loaded.

Rolling your own 'require' function should be straightforward.

Tom Skwara
MobileApp Systems



Reply all
Reply to author
Forward
0 new messages