love-android + dofile in *.love

A project to port LÖVE to Android handhelds
Locked
User avatar
4aiman
Party member
Posts: 218
Joined: Sat Jan 16, 2016 10:30 am

love-android + dofile in *.love

Post by 4aiman » Sat Jan 16, 2016 12:00 pm

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.

User avatar
bartbes
Sex machine
Posts: 4871
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: love-android + dofile in *.love

Post by bartbes » Sat Jan 16, 2016 12:38 pm

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.
Cowardly acts and the eating of birds must not be the deeds of a Hero of Storms.

User avatar
4aiman
Party member
Posts: 218
Joined: Sat Jan 16, 2016 10:30 am

Re: love-android + dofile in *.love

Post by 4aiman » Sat Jan 16, 2016 12:48 pm

The thing is, when i write

Code: Select all

require "menu.lua"
i got this:
Image

User avatar
bartbes
Sex machine
Posts: 4871
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: love-android + dofile in *.love

Post by bartbes » Sat Jan 16, 2016 12:51 pm

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".
Cowardly acts and the eating of birds must not be the deeds of a Hero of Storms.

User avatar
4aiman
Party member
Posts: 218
Joined: Sat Jan 16, 2016 10:30 am

Re: love-android + dofile in *.love

Post by 4aiman » Sat Jan 16, 2016 12:56 pm

Oh..
Thanks, bartbes!

Locked

Who is online

Users browsing this forum: No registered users and 1 guest