Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
why cant require() stupid lua file? — Gideros Forum

why cant require() stupid lua file?

jack0088jack0088 Member
edited February 2013 in General questions
I cannot require("folder/file"), Why? It's a simple file.lua inside main project directory in a folder with content:
return {[1] = "hello world"}
error:
no field package.preload['folder/file']
no file './folder/file.lua'
<b>...</b>
The file mentioned above is not included into Gideros Studio Project, because I plan to create them on Runntime and require() or delete again.
Is there a way of loading custom/normal modules and such lua files... ?

Dislikes: Yan

Owltwins. Smart design and creative code.
»Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
+1 -1 (+0 / -1 )Share on Facebook

Comments

  • atilimatilim Maintainer
    Accepted Answer
    Here, you need to write
    require "scenes.level1"
  • jack0088jack0088 Member
    edited February 2013
    @atilim thank you for the hint. but still doesn't work, I think because it's not included into the projekt. but here's the point... I mentioned it above. I want create and read/modify lua files at runntime, So including into the project tree manually is not an option.
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • atilimatilim Maintainer
    edited February 2013
    If it's stored at documents/temporary directory, there may be no way to load with require. Can you use dofile instead?
  • atilimatilim Maintainer
    edited February 2013 Accepted Answer
    Also if you're creating and deleting Lua files, require can give some problems. Because require caches the return value of the executed file and won't run again even if you delete and recreate it.
  • nope. it's in same folder as gideros project. so its project folder, there is the main.lua inside AND a sub-folder where finally my desired file lives.

    -Gideros Project
    --main.lua
    ---folder
    ----file.lua <-here!
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • atilimatilim Maintainer
    edited February 2013
    I may not understand correctly.

    - If you're creating the file at runtime, it should be stored at documents or temporary directory.
    - If it's added to the project (placed in resource directory), you cannot delete or modify it and can be loaded with require "folder.file".
  • jack0088jack0088 Member
    edited February 2013
    ahhh... ok. so i cant even create it where i planed it.
    If it is in the documents, how do i require it then?

    The thing is: Regardless, It would be awesome having require() work for everythign, without including it into the project tree inside GiderosStudio. Similar to what cor.SDK does. Everything require() and your done.
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • atilimatilim Maintainer
    Accepted Answer
    > If it is in the dicuments, how do i reaquire it then?
    You can't. It seems dofile or loadfile is the only way. (also if you're creating/modifying Lua files at runtime, I don't recommend using require because it caches the return value).
  • jack0088jack0088 Member
    edited February 2013
    good to know.
    how about hassle-free ide for gideros? automatic project management, I mean. something that abandons this annoying manual file addition to the project tree...
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • atilimatilim Maintainer
    Currently, I don't prefer automatic inclusion of all Lua files. It gives you less control about the project.
  • jack0088jack0088 Member
    edited February 2013
    Do you think so? The IDE would just read the whole project directory in (sub-folders incl.) and then you always could set code dependencies and other stuff. Where is the problem?
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • atilimatilim Maintainer

    The thing is: Regardless, It would be awesome having require() work for everythign, without including it into the project tree inside GiderosStudio. Similar to what cor.SDK does. Everything require() and your done.
    As far as I know, with Corona, you can only require the files packaged with the project. Also you cannot call dofile/loadfile. Therefore it's impossible to create files at runtime and load them. (Correct me if I'm wrong.)

  • atilimatilim Maintainer
    edited February 2013
    Do you think so? The IDE would just read the whole project directory in (sub-folders incl.) and then you always could set code dependencies and other stuff. Where is the problem?
    It's a matter of taste. For example, Gideros runtime contains >500 source files and every IDE I'm using (Qt Creator, Visual Studio, XCode, manually created makefiles) requires managing all these files manually and I'm really happy with it.
  • jack0088jack0088 Member
    edited February 2013
    @C.SDK: Yes, but you always free to require every module, shipped with lua or your custom ones, as long as they live inside lua's search path. And this is something Gideros doesn't have. You always have to manage manually what to include. My external modules (dynamic loading) wont load until today... Nothing dynamic seems to work.. Kind of demotivating for me. Or maybe I'm just to stupid to get it right...
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • atilimatilim Maintainer
    Accepted Answer
    With Corona, is there a way to create and run a Lua file at runtime?
    As far as I know:
    1. All Lua files that can be loaded with require should be packaged beforehand.
    2. There is no dofile/loadfile.
  • jack0088jack0088 Member
    edited February 2013
    accepted :) nevertheless .. i would like to see more dynamics, with less ado. anyway thank you very much for the discussion:))
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • Just to add my $0.02 - firstly think of your app and your app's resource folder as READ ONLY, you can't create any documents in there, that's what the document / temp folders are for. This is due to the sandboxing restrictions that Apple and Android place on their apps and there's no way round it (nor should you want to).

    As for the creation, download etc of dynamic lua files using doFile or loadFile, I'd also strongly advise against it. Apple's TOS explicitly forbids this kind of behaviour to stop any kind of post install, code download either malicious or not (in theory you could create your own in app appstore, or significantly change the behaviour of your app), so any app that appears to do this WILL get rejected by Apple.

    If you want to share what it is your trying to achieve then I'm sure there are plenty of experienced people here who'll happily give you some pointers to steer you in the right direction.
    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
  • Vote against automatic file management (like adding to the project), because then it will make hard for you to manage multiple projects with same assets and code, like Lite and Premium versions, or Iphone and Ipad versions from the same folder reusing most of the same files. It is better done manually. One that might be needed, is a way to add multiple files. :)

    Likes: techdojo

    +1 -1 (+1 / -0 )Share on Facebook
  • Vote 2 against automatic inclusion of files. I have a number of folders of standard functions and assets on my computer and love the way I can pull things into my project from these without having to first copy them into some project folder. I admit I often create a new graphic (or whatever) in one of my source folders and forget to add it to the project, but then I'm soon reminded when I try to run the thing :)

    Likes: techdojo

    +1 -1 (+1 / -0 )Share on Facebook
  • john26john26 Maintainer
    @atilim "every IDE I'm using (Qt Creator, Visual Studio, XCode) requires managing all these files manually"

    It's worth noting that Eclipse (the IDE you didn't mention :-) ) does not require manual file management. In Eclipse you merely nominate a directory and all contents are automatically part of the project (the .project file does not contain a list of source files). Of course, you could end up with a lot of crud in your project. Eclipse deals with this by creating and managing its own filesystem in the workspace directory (if you create a new project in Eclipse). But if you import an existing project into Eclipse it just sucks everything up.

    This behaviour is useful when developing for Android since I can reexport from Gideros and then just refresh the project in Eclipse. New resources or Lua files will automatically be added. I don't have to tell Eclipse "please add this file".

    So this automatic inclusion approach is useful when one IDE acts as the backend for another (as Eclipse does for Gideros IDE). But it may not be best for the "primary" IDE.
  • FWIW - I agree with Arturs and @john26, yes it can be awkward to have to manage the settings yourself, but often times you end up with a load of extra crap in the resource directories that you don't want necessarily included in the final build.

    If you look at what happens when you run an app, the contents of the project listing get copied over (if newer) to the runner so there IS a kind of automatic project management going on.
    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
Sign In or Register to comment.