Either my tiled STI is broken or im an idiot

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Either my tiled STI is broken or im an idiot

Post by Karai17 »

For the record, this has been resolved. powerII was originally dumping the contents of STI directly into his root folder, so requiring "sti" was not possible. The setfenv issue occurred because requiring init.lua causes sti to behave oddly. It is important to leave sti and any other module that has an init.lua within a folder, and just require the folder.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
pgimeno
Party member
Posts: 3713
Joined: Sun Oct 18, 2015 2:58 pm

Re: Either my tiled STI is broken or im an idiot

Post by pgimeno »

Karai17 wrote:It is important to leave sti and any other module that has an init.lua within a folder, and just require the folder.
Haven't tried yet, but for future and while on this subject, does this mean that one can't use: require "sti.init"? Or move sti/init.lua to sti.lua and still do: require "sti"?

I ask because support by default for ?/init.lua in the path has been removed in Lua itself, even if it's still kept in love2d, so I'm trying to avoid depending on it.
User avatar
slime
Solid Snayke
Posts: 3181
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Either my tiled STI is broken or im an idiot

Post by slime »

pgimeno wrote:Haven't tried yet, but for future and while on this subject, does this mean that one can't use: require "sti.init"? Or move sti/init.lua to sti.lua and still do: require "sti"?
init.lua can't be renamed without modifying STI's code I believe, but you should be able to do require("sti.init"): https://github.com/karai17/Simple-Tiled ... it.lua#L15
pgimeno wrote:I ask because support by default for ?/init.lua in the path has been removed in Lua itself, even if it's still kept in love2d, so I'm trying to avoid depending on it.
I believe package.path always looked for ?/init.lua in the system directories it looks in, but "./?/init.lua" (i.e. looking for init.lua relative to the current working directory) was actually added to package.path in Lua 5.3 ( http://www.lua.org/source/5.2/luaconf.h ... TH_DEFAULT versus http://www.lua.org/source/5.3/luaconf.h ... TH_DEFAULT ).

Also keep in mind that LÖVE doesn't use package.path at all when looking for files in love.filesystem paths when require is used. LÖVE adds its own searcher to the package.loaders table (which require iterates over), and [wiki]love.filesystem.setRequirePath[/wiki] can be used in a similar manner to package.path.
A function (provided by Lua itself) which looks through package.path is also in the package.loaders table separately.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Either my tiled STI is broken or im an idiot

Post by Karai17 »

You cannot remove init.lua or rename it to sti.lua. The file relies on another file within, map.lua, and the plugin files (optionally). The path finding in STI relies on the current file structure.

I highly doubt Lua would remove such a prominent feature and completely disrupt their whole ecosystem on a whim. ?/init.lua has been around for quite a long time, and very many modules are designed with that in mind. Namely anything that is larger than a single file.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
pgimeno
Party member
Posts: 3713
Joined: Sun Oct 18, 2015 2:58 pm

Re: Either my tiled STI is broken or im an idiot

Post by pgimeno »

With my apologies in advance for the slight topic drift:

@slime:
slime wrote:I believe package.path always looked for ?/init.lua in the system directories it looks in, but "./?/init.lua" (i.e. looking for init.lua relative to the current working directory) was actually added to package.path in Lua 5.3 ( http://www.lua.org/source/5.2/luaconf.h ... TH_DEFAULT versus http://www.lua.org/source/5.3/luaconf.h ... TH_DEFAULT ).
Yes, that's what I meant. I must have misunderstood this post, then: http://lua-users.org/lists/lua-l/2009-04/msg00389.html and since it wasn't present in my Lua 5.1 and it's quite old, I assumed it was present before and removed.

The arguments in that post and the two linked posts sounded reasonable and I thought that it was a good policy to avoid depending on ./?/init.lua to be in the path.

@Karai17:
Karai17 wrote:You cannot remove init.lua or rename it to sti.lua.
Sorry, that's not what I was suggesting. I was suggesting to move sti/init.lua to sti.lua, such that the tree would look like:

Code: Select all

sti.lua  (old sti/init.lua)
sti/map.lua
sti/plugins/box2d.lua
sti/plugins/bump.lua
such that 'require "sti"' would work even if ./?/init.lua is not in the path.
Karai17 wrote:I highly doubt Lua would remove such a prominent feature and completely disrupt their whole ecosystem on a whim. ?/init.lua has been around for quite a long time, and very many modules are designed with that in mind. Namely anything that is larger than a single file.
Well, in Linux command line (Lua 5.1):

Code: Select all

mkdir x
> x/init.lua
echo 'require "x"' > main.lua
Running: 'lua main.lua' results in:

Code: Select all

$ lua main.lua
lua: main.lua:1: module 'x' not found:
	no field package.preload['x']
	no file './x.lua'
	no file '/usr/local/share/lua/5.1/x.lua'
	no file '/usr/local/share/lua/5.1/x/init.lua'
	no file '/usr/local/lib/lua/5.1/x.lua'
	no file '/usr/local/lib/lua/5.1/x/init.lua'
	no file '/usr/share/lua/5.1/x.lua'
	no file '/usr/share/lua/5.1/x/init.lua'
	no file './x.so'
	no file '/usr/local/lib/lua/5.1/x.so'
	no file '/usr/lib/i386-linux-gnu/lua/5.1/x.so'
	no file '/usr/lib/lua/5.1/x.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
	[C]: in function 'require'
	main.lua:1: in main chunk
	[C]: ?
while running 'love .' works without problems.
User avatar
slime
Solid Snayke
Posts: 3181
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Either my tiled STI is broken or im an idiot

Post by slime »

pgimeno wrote:Well, in Linux command line (Lua 5.1):
As I demonstrated above, ".?/init.lua" is simply missing from the default package.path in Lua versions prior to 5.3 (it was added in 5.3). It does look for init.lua in its search paths outside of the current working directory though.

The package.path on my Lua 5.1 interpreter is this:

Code: Select all

./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua
You could write a couple lines to look through package.path and add ";.?/init.lua" if it doesn't exist, if you want it to work outside of LÖVE. package.path is meant to be modified / extended.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], KIRINGAMES and 5 guests