Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Newbie Lua Problem with require - How to do require — Gideros Forum

Newbie Lua Problem with require - How to do require

Hi! I have a very simple question.

How can I use require in Gideros for a Lua file in my project?

I tried with: (assuming elements.lua is next to main.lua)

local elements = require("elements")
local elements = require("elements.lua")
I also had two different files and tried:

Using a relative path
Using dots as separators
Using the full path from assets
But nothing worked.

Can someone please give me an example? Sorry for the basic question, but this error is driving me crazy, and I don't want to solve it using global variables.

[string "luabinding/compatibility.lua"]:82: Module elements.lua not found
stack traceback:
[string "luabinding/compatibility.lua"]:82: in function require
main.lua:3:

Please Help
Tagged:

Comments

  • MoKaLuxMoKaLux Member
    edited January 28 Accepted Answer
    I will try to help :)

    Assuming I have a file called level01.lua in a "tiled" folder:
    return {
      version = "1.10",
      luaversion = "5.1",
      tiledversion = "1.11.0",
      class = "",
    ...
    }
    In some other place I can call this file using require:
    local tm = require("tiled/level01") -- without ".lua" extension
    But I don't know what your "elements.lua" looks like :|

    You may also need to add exclude from execution at the top of your "elements.lua" file?
    --!NOEXEC
    -https://wiki.gideros.rocks/index.php/Loading_Order_of_Lua_Files
    -https://wiki.gideros.rocks/index.php/Require

    Hope this helps?

    Likes: zeroexu

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • Thank you very much!

    It worked.

    I needed to use
    --!NOEXEC
    in the file to be imported,

    and in the file that uses require:
    --!NEEDS:your_file.lua

    And that's it!
    Thank you so much!

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.