This is mainly a question aimed at
@Atilim &
@Gorkem however I'd appreciate input from any Lua experts out there.
I've noticed that the example programs do not use the Lua "require" function to load in external modules and in my own current demos I tend to wrap everything up in Classes and it just seems to work (granted I am aware of the code dependency setting in Studio), so my question is, does the code dependency setting mean that you don't need to use the require function anymore? if so how do you get round circular dependencies?
I'm starting to write a generic skinnable UI library (called widget) and normally (in Corona or other Lua frameworks) I'd plan on using the require function to load the module into the main package.loaded table to make it available either in the global namespace
require "widget"
button = widget.newButton(...) |
or as a local reference
local widget = require "widget"
button = widget.newButton(...) |
Where widget.lua would look something like this...
local widget = {}
function widget.newButton(options)
return Button.new(options)
end
-- etc etc
return widget |
The above is basically a factory that just wraps each widget control (most probably a class that's derived from a sprite or a bitmap) and returns it in a consistent manner.
Is it worth using the require function or would it be better to just force the widget.lua function to be loaded first?
WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
#MakeABetterGame! "Never give up, Never
NEVER give up!" -
Winston Churchill
Comments
and afaik, this usage:
But if you're planning to implement a widget library, most probably you will need clipping functionality :-\" heheh
edit: hmm.. I was wrong about global reference. I mean in widget.lua, you should write as:
How does the use "require" fit in with the "normal" Gideros setup which I assume is based on the fact that as each file is "loaded" in the order specified any globals, functions etc are parsed as they are found, added to the global namespace and as such are then recognised as needed (I was going to say required but I thought that might get confusing )
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
I often use my downloader on my iPad to load projects from Dropbox and bypass the Gideros IDE completely and so when I open the example projects I have to manually add the requires.
My apps: http://www.yummyyellow.com
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
http://blog.magnusviri.com/gideros-downloader.html
My apps: http://www.yummyyellow.com
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
http://news.ycombinator.com/item?id=4083768
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
@techdojo you're totally correct. but when the users call
You just need to right click on .lua file and select "Exclude from execution". So that this .lua file won't be executed at the beginning of the application and you can use require to load it anytime you want. (If you don't select "Exclude from execution", it will be executed twice: once at the beginning and when require function is used)
I must remember to reorganise my project files and then keep all "data" files in a separate folder so that I can "exclude" them from execution.
Thanks for the tip!
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
local socket = require "socket": return socket module
local socket = require "src/socket": return boolean value
Likes: ar2rsawseen, phongtt
http://stackoverflow.com/questions/15988268/calling-functions-on-required-modules-in-lua-gives-me-attempt-to-index-local
true is usually returned by require if module function is not used inside module and module code doesn't return a value.
But anyway it seems strange.
but if its in a folder. require("includes/module.lua")]
it fails.
Any ideas?
---------------------------------------
https://play.google.com/store/apps/developer?id=Into-It+Games
http://appstore.com/LidiaMaximova
Are you excluding the file in your project properties?