Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Why are modules executed by Gideros at startup not using Lua package manager? — Gideros Forum

Why are modules executed by Gideros at startup not using Lua package manager?

troysandaltroysandal Member
edited December 2013 in General questions
I've been working around this problem for some time and would like to ask the masters of Gideros why it is that packages executed by Gideros at startup don't go into the package manager? This is causing my modules to be evaluated by the Lua interpreter twice which seems inefficient and forces me to either use excludefromexecution="1" for all files or to guard against double evaluation using a sentinel value. This can be very bad if you're doing one-time initialization of say, installing listeners and timers, which are then doubled since the package manager wasn't used.

Is there some reason why this would be needed? I'm still new to Lua so perhaps there's a simple answer I'm just not seeing, apologies in advance if so.

To see this in action here's an example, say you have 2 files, test.lua and main.lua. test.lua assumes it will only be evaluated once at startup or during the first require 'test.lua'. You'll see 2 different values for test printed out.

test.lua
local test = math.random()
print("test.lua loaded, value set to "..test)
return test
main.lua
local test = require 'test'

Comments

  • the whole structure of your app is not meant to consist of modules in Gideros.
    In Gideros you should use the scenes to divide logic of the app, and some other objects as game elements using as Gideros classes in Gideros OOP style, thus they can easily be executed on start.

    If you are using some specific lua libraries that are based on lua modules, then yes you will have this problem and you should either exclude them from execution, which I think is a normal request for a 3rd party module added to the project, or create them the way, they will automatically create the global variable on start and you won't have to require them later (look at dataSaver https://github.com/ar2rsawseen/dataSaver/blob/master/dataSaver.lua).
  • I am using scenes and I'm using Core.class() to create Gideros style classes, I think that's orthogonal to this issue of why Gideros doesn't use the package manager/require when executing modules. I decided to not declare everything as a global and instead rely upon modules via the require and the package manager per the Lua 5.1 and 5.2 recommendation.

    I get that Gideros loads everything by default so all classes are ready once main.lua is invoked but I don't see why it would bypass the package manager. Seems it would be as as setting _G.package.loaded["Module"] = ... while Gideros is executing modules during startup.

    Or is that impossible for Gideros to do?
  • I'm sorry I really don't get the issue then
    Gideros executes all files, which are not set (Do not execute), including the files that contain modules

    And then if you require the module again, of course this file gets executed again.

    I don't think that Gideros changes any module behavior.

    What would be the expected behavior in your opinion?
  • My expectation here is that Gideros would use the require statement to load every module for execution so that the package manager would cache them, preventing double execution of any files. I think that expectation, however, is at odds with how Gideros was built and how I built my project. Letting the package manager cache modules would stop double executions but it seems that's just my problem with my project structure. For me that means setting every file to excludefromexecution="1", less optimal but fixes my issues.

    Thanks for your explanations.
Sign In or Register to comment.