6
\$\begingroup\$

I'm building an engine in Love2D and I need to build an editor who will create scenes with game objects I wrote in lua.

The thing is that there's this guy in my team who said : "Don't include the editor within the game, make it separate from it so you won't load the whole editor with the game itself"

So I'm asking how could I achieve this type of structure, because I want my libraries to be shared between the game and the editor.

- MAIN FOLDER 
    | - core
    |   | core features of the engine
    | - editor
    |   | main.lua
    | main.lua

I can't see how I'll be able to require files with this structure, is there a specific way to do this kind of thing in lua ?

What I'm trying to do now is this :

main.lua (game)

require "core/engine"

function love.load()  -- This works
    print("Loaded")
end

main.lua (editor)

require "../core/engine"

function love.load() -- Won't work
    print("Loaded")
end
\$\endgroup\$
5
\$\begingroup\$

Alright, found it !

I had to add this to the main.lua file in the editor folder and it worked :

package.path = package.path .. ";../?.lua"
require "core.engine"
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.