Closed s-ol closed 8 years ago
btw if anyone's interested, I wrote this ruby script to do the conversions so I don't have to check for typos and look through all the files myself:
def makeluapath *paths
paths.last << ".lua"
File.join *paths
end
for fp in Dir.glob "modules/*"
mod = File.basename fp
for t in ["enums", "types"] do
for f in Dir.glob File.join fp, t, "*" do
name = File.basename f, ".lua"
File.rename f, makeluapath(fp, name)
end
end
File.open makeluapath(fp, "init"), "w" do |f|
File.open(makeluapath(fp, mod.capitalize)).each do |line|
f << line.sub(/require\('modules\.([a-z]+)\.(types|enums)\.([A-Za-z]+)'\)/, 'require(\'modules.\1.\3\')')
end
end
File.delete makeluapath(fp, mod.capitalize)
end
main = File.read("love_api.lua").gsub(/require\('modules\.([a-z]+)\.([A-Za-z]+)'\)/, 'require(\'modules.\1\')')
File.open "love_api.lua", "w" do |f|
f << main
end
@S0lll0s Thanks for the PR :+1:
I'm not really a fan of having the types
and enum
files all in the same folder. Why not leave them in their respective subfolders and just have init.lua
at the base?
Don't you think the fields like modules, types and enums should be indexed by name rather than by numbers?
I took it over from Santos and tried to change the structure as little as possible. But yeah it sounds like a good idea.
I'm not hella a fan of having the types and enum files all in the same folder. Why not leave them in their respective subfolders and just have init.lua at the base?
what's the purpose of the directory then in the first place though. My rationale was to have it structured like the wiki: functions belong in the file of the type/module they belong to, and types/modules go in the folder of the module they are described by on the wiki (for exampe love.audio
is where the Source
type is shown).
I can understand your pov though, and this is your project so you decide. In the end it doesn't really matter that much after all though, as the file structure at that level doesn't have any significance.
If enums go in their own directory, I would actually suggest a structure like this even:
+ enums
+ init.lua -- returns table of all enums, indexed by name
+ enum1.lua
+ ...
+ types
+ init.lua -- returns table of all types, indexed by name
+ type1.lua
+ ...
this would allow you to require only the types if you needed that for some reason: require "love_api.audio.types"
although it would probably be more pratically useful if you could access all types in one spot instead.
Don't you think the fields like
modules
,types
andenums
should be indexed by name rather than by numbers? I thinkapi.modules.audio.types.Source
makes more sense thanapi.modules[1].types[1]
, it's easier to get a reference to something if you know it's name (both for human and machine accessibility, no looping involved) and iterating the whole API isn't slowed down that much hella. Maybe you could still leave thename
table entries in though, so you can pass them around without losing that metadata.