Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Modules should be excluded from execution? — Gideros Forum

Modules should be excluded from execution?

bowerandybowerandy Guru
edited September 2012 in General questions
I'm not sure whether this is a question or a statement of fact but I've found that, if I create a module with the standard declaration:

module(..., package.seeall)

and just include the file in a project, then I get an error when trying a run:

"bad argument #1 to 'module' (string expected, got nil)"

I guess this is because Gideros, by default, loads all files at the beginning of a run and so no parameter name is being transferred to the module declaration. The solution appears to be to right click on the module file in the IDE and choose "Exclude from Execution" so that Gideros doesn't automatically run the file. Then accessing the module using require "modulename" works as normal.

Is this expected behaviour when using modules with Gideros? I'm sorry if this is an obvious question but I don't tend to use modules much - having switched almost entirely over to using Gideros classes.

Best regards

Comments

  • Hmm, since first parameter supposed to be string, shouldn't it be
    module("...", package.seeall)
    or ... is kind of internal constant?
  • @ar2rsawseen, I've been going by this:

    http://lua-users.org/wiki/ModulesTutorial

    I think they just use the ellipsis to avoid having to retype the actual module name.

    Best regards
  • atilimatilim Maintainer
    Accepted Answer
    Ellipsis (...) is used to pass variable number of arguments. There is some explanation here: http://pgl.yoyo.org/luai/i/2.5.9+Function+Definitions

    Although I don't know modules much, excluding the file is the correct way.
  • @atilim, thanks. I'm not too keen on modules myself either but I'm using some 3rd party code that makes use of them. Actually, I've discovered that I can use the "lightweight module" scheme successfully with this code anyway:
    local MyModule={}
     
    function MyModule.func1()
    end
     
    return MyModule
  • CyberienceCyberience Member
    edited January 2013
    What is Modules(...) used for?
    REAL programmers type copy con filename.exe
    ---------------------------------------
  • it is used to load chunks of code on demand. so you can use
    require "modulename"
    to add that module. With Gideros since all of the Lua files are loaded and executed, you do not have the need of Modules any more.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • HubertRonaldHubertRonald Member
    edited June 2014
    Hi folks!

    For example if in your app, you've 60 or more files of tilemaps (they are only tables) exclude them from execution can improve "watchdog timer" (iPhone, iPad) but I don't know if it can affect performance the app because these levels (tables) not have been previously loaded. (The real problem is restart the same level and load again the same table)

    Although on the other hand, it's unlikely that a user can play 60 or more levels at once.

    But any suggestion thanks.

    P.S. each level file Tilemap.lua has 1000 lines... in total it should be 60000 lines or more.
  • Hi... Can somebody help me with my question above?
    @OZApps, @ar2rsawseen or somebody more

    Thanks
  • ar2rsawseenar2rsawseen Maintainer
    @HubertRonald and do you have a problem with a "watchdog timer" timer on ios?

    What I did in Mashballs, was creating separate files for each level, and then upon starting a level, I loaded the specific level definition file. The files were not lua, so they were not executed automatically, and I had to read the contents using io, thus the contents were only stored in the memory, while parsing it and interpreting it/ generating level and then got rid of it.

    And it seems to work great :)
  • HubertRonaldHubertRonald Member
    edited June 2014
    Hi @ar2rsawseen
    Actually I'm tweaking the code so I have excluded files levelTilemap.lua, but these are loaded... on the other hand files types json, *. otf or *. txt can't be excluded of project.

    I guess despite levelTilemap.lua were excluded files as these have a direct dependence on the creator of levels Class, they will be loaded (please correct me if I'm wrong) but excluding other *. Lua unrelated to anything for example testMen.lua (it's a class) when I run the code first time Gideros Player with Mac doesn't load.

    Furthermore, if I'll use levelTilemap.txt (it can't be excluded)... hmm issue is that the data are tabulated and there are variables with data and extract the information in that form would be a big headache.
    --[[
    --------------------
    file: levelTilemap.lua
    --------------------
     
    height=4
    {0,1,2,3,4,5,6,7,8,9}
     
    ]]
     
    local file = io.open("levelTilemap.txt")
    local tbllines = {}
    local i = 0
    if file then
        for line in file:lines() do
         i = i + 1
         tbllines[i] = line
        end
        file:close()
    else
        error('file not found')
    end
     
    for k, v in pairs(tbllines) do
     print("->",v)
    end
     
    --[[
    --------------------
    I got
    --------------------
    ->	height=4
    ->	{0,1,2,3,4,5,6,7,8,9}
    ]]
    So in my case it doesn't work exclude levelTilemap.lua (for improve "watchdog timer") or maybe I miss something.
  • ar2rsawseenar2rsawseen Maintainer
    non lua files can't be excluded, because they can't be executed, as in, they are not executed at all
    lua files are executed/ran by default, running everything that is inside, if lua file is excluded it is not ran, until required in some other file using require command.

    Basically, it seems that tilemaps are not your problem with watchdog timer, but something else, possible large graphic files
  • HubertRonaldHubertRonald Member
    edited June 2014
    Thanks my best, I only wanted improve watchdog timer, but maybe exclude levelTilemap.lua isn't right way, because these files are loading so they are excluded because MultiTilmap.lua Class has
      local map = loadfile("Levels/levelTilemap.lua")()
    So I'm going to encoder of iTunes for resize my mp3 files and I can get improve a little more the watchdog timer, because my images are grouped on texture packer of 1024x1024 as you suggested me, some weeks before. :D

    Thanks again :)>-
Sign In or Register to comment.