Page 1 of 1

love-android + dofile in *.love

Posted: Sat Jan 16, 2016 12:00 pm
by 4aiman
Hello there!


I know there are tons of dofile-related questions and threads, but I wasn't able to find answer to my question.

There's a *.love file which runs perfectly on Linux (Debian Jessie) with the LÖVE 0.1.10 (built from sources), but fails to execute on Android device.

The "main.lua" file starts with:

Code: Select all

debug = true

local debug_file = io.open("debug.txt")

game = {}
game.animations = {}
game.previous_level = nil
game.current_level = 1

game.started = false
game.in_menu = true
game.font = love.graphics.newFont("pixel.ttf", 18)

dofile("menu.lua")
dofile("tbl_ser.lua")
game.anim8 = require 'anim8/anim8'
*Note the line with dofile("menu.lua").

While it's "ok" on full-fledged Linux, on Android I'm getting the

Code: Select all

main.lua:15: module 'menu.lua' not found
error.

If I were opening just a main.lua file...
Then my guess would have been the error occurred due to a wrongly set working dir...
But I'm running a *.love file! Does LÖVE for android unpack content of a love file to some temp dir?

Hom am I supposed to use multiple files on Android?

Note:
The menu.lua file can't be loaded by "require" as is.
"menu.lua" is not really a library but rather a saved separately menu-related code.

Re: love-android + dofile in *.love

Posted: Sat Jan 16, 2016 12:38 pm
by bartbes
dofile does not work with love.filesystem. It working on your linux machine is simply an artefact of where you're running it from, the same directory as menu.lua. Either use love.filesystem.load, and call the returned function, or use require anyway. I see no reason why your file can't be loaded with require, as it puts no restrictions on the file.

Re: love-android + dofile in *.love

Posted: Sat Jan 16, 2016 12:48 pm
by 4aiman
The thing is, when i write

Code: Select all

require "menu.lua"
i got this:
Image

Re: love-android + dofile in *.love

Posted: Sat Jan 16, 2016 12:51 pm
by bartbes
Because require doesn't take filenames, it takes module names. To turn a module name into a path, you replace all dots with slashes, and append .lua, so, "menu.lua" looks for the file "menu/lua.lua". Instead, you want to pass it "menu".

Re: love-android + dofile in *.love

Posted: Sat Jan 16, 2016 12:56 pm
by 4aiman
Oh..
Thanks, bartbes!