Closed davisdude closed 1 year ago
Hello,
Do you have proposed solution on how to fix this problem?
There are two possible ways that I've thought of. Each has been tested with the following script:
local api = require('love_api')
print(#api.modules[1].types)
Currently, using Lua 5.4, this script will return 3, unless one of the fixes is used, in which case it returns 2, as expected.
Put nil
after the last require
of each table, preventing the second value from coming through. E.g.
local path = (...):match('(.-)[^%./]+$')
return {
name = 'audio',
description = 'Provides an interface to create noise with the user\'s speakers.',
types = {
require(path .. 'types.RecordingDevice'),
require(path .. 'types.Source'),
+ nil,
},
-- ...
Assign all require
d variables outside of table creation, allowing the second return value to be dropped. E.g.
local path = (...):match('(.-)[^%./]+$')
+local RecordingDevice = require(path .. 'types.RecordingDevice')
+local Source = require(path .. 'types.Source')
return {
name = 'audio',
description = 'Provides an interface to create noise with the user\'s speakers.',
types = {
- require(path .. 'types.RecordingDevice'),
+ RecordingDevice,
- require(path .. 'types.Source'),
+ Source,
},
-- ...
You could also monkey-patch and/or write your own require
function that always tosses the second return value, but that I'm not a huge fan of that approach.
What about surrounding the require
in a parenthesis such as (require(path .. 'types.RecordingDevice'))
?
That would also work - there are a few ways this could be addressed.
As of Lua 5.4,
require
returns a second value.Docs of
require
for Lua 5.3:Docs of
require
for Lua 5.4 (emphasis mine)If using Lua 5.4 or greater, this breaks many scripts that rely on each module being a valid table object. This is because many of the tables, e.g. types / enums, are just made by calling
require
on the constituent objects. For example an example of how this breaks things, see, vim-love-docs.