Require relative Lua file

If i have a .gui_script and a .lua in the same folder, how can I require the .lua using relative folder?
Like “import” in quick-cocos2dx.

You can’t. You need to provide the absolute path (from root of project) to the lua file.

Why do you need this?

1 Like

I’m making a “module”, it include a game object,script,gui,and gui_script,and a lua module. This “module” may be moved to another folder,so I need to change the require path.

1 Like

Ah, I see. Well, Defold resolves all requirements and dependencies at compile time in order to determine what files to include. That is why Lua files need to be required using absolute paths. We scan all files for requires and includes only those *.lua files that are required through code.

1 Like

For improvement, I think defold can give a new require,using relative path, for example:
import(".my_module")
It will resolve the relative path from which script or gui_script the import in.

2 Likes