Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing variants which are redundant due to default arguments in other variants #49

Open
hahawoo opened this issue Aug 5, 2017 · 1 comment

Comments

@hahawoo
Copy link
Contributor

hahawoo commented Aug 5, 2017

For example, love.physics.newMotorJoint currently has two variants:

love.physics.newMotorJoint(body1, body2, correctionFactor [default: 0.3])
love.physics.newMotorJoint(body1, body2, correctionFactor [default: 0.3], collideConnected [default: false])

when really it has one variant, because the "collideConnected" argument has a default.

The functions I found which might be in this category are:

love.filesystem.mount (appendToPath default is false)
love.graphics.arc (ArcType default is "pie")
love.graphics.circle (segments has a default)
love.graphics.ellipse (segments has a default)
love.graphics.newFont (size default is 12)
love.graphics.newImage (has default flags)
love.graphics.newImageFont (extraspacing default is 0)
love.graphics.rectangle (rx default is 0)
love.graphics.setBlendMode (BlendAlphaMode default is "alphamultiply")
love.keyboard.isDown (extra keys are optional)
love.math.random (min default is 1)
love.physics.newMotorJoint (collideConnected is false)
love.physics.newPrismaticJoint (reference angle is 0)
love.physics.newWeldJoint (reference angle is 0)
love.window.setFullscreen (fstype is "desktop" or last used)
Joystick:setVibration (duration is -1)

This can be corrected in the wiki as well, however sometimes it might not always be appropriate to remove the variant from the wiki because the wiki retains information about all LOVE versions and the variants may have been added in different versions. If there are any instances of this I think love-api should differ from the wiki and remove them anyway because love-api only contains information for the version which it targets.

There is also another concept which the wiki doesn't currently use which is that an argument can be left out, i.e. be "none". I'm not suggesting we do anything about this necessarily, I just thought it was interesting:

love.image.newImageData (data can be none)
love.graphics.newMesh (vertexformat can be none)
love.joystick.saveGamepadMappings (file can be none)

If anyone is interested, here is a script which prints out functions which have more than one variant that I used to find the functions above:

api = require('love-api.love_api')

function printFunctions(functions, parent)
  for _, function_ in ipairs(functions) do
    if function_.variants and #function_.variants > 1 then
      for _, variant in ipairs(function_.variants) do
        local output = ''
        for returnIndex, return_ in ipairs(variant.returns or {}) do
          output = output..return_.name
          if returnIndex ~= #variant.returns then
            output = output..','
          end
          output = output..' '
        end
        if variant.returns then
          output = output..'= '
        end
        output = output..parent..function_.name..'('
        for argumentIndex, argument in ipairs(variant.arguments or {}) do
          output = output..argument.name
          if argument.default then
            output = output..' ['..argument.default..']'
          end
          if argumentIndex ~= #variant.arguments then
            output = output..', '
          end
        end
        output = output..')'
        print(output)
      end
    end
  end
end

printFunctions(api.functions, 'love.')

for _, module_ in ipairs(api.modules) do
  printFunctions(module_.functions, 'love.'..module_.name..'.')
  for _, type_ in ipairs(module_.types or {}) do
    if type_.functions then
      printFunctions(type_.functions, type_.name..':')
    end
  end
end

And the output is:

source = love.audio.newSource(filename, type ["stream"])
source = love.audio.newSource(file, type ["stream"])
source = love.audio.newSource(decoder, type ["stream"])
source = love.audio.newSource(soundData)
source = love.audio.newSource(fileData)
love.audio.pause()
love.audio.pause(source)
love.audio.resume()
love.audio.resume(source)
love.audio.rewind()
love.audio.rewind(source)
love.audio.stop()
love.audio.stop(source)
love.event.quit()
love.event.quit(exitstatus [0])
love.event.quit("restart")
success = love.filesystem.mount(archive, mountpoint)
success = love.filesystem.mount(archive, mountpoint, appendToPath [false])
data = love.filesystem.newFileData(contents, name, decoder ["file"])
data, err = love.filesystem.newFileData(filepath)
success, message = love.filesystem.write(name, data, size [all])
success, message = love.filesystem.write(name, data, size [all])
love.graphics.arc(drawmode, x, y, radius, angle1, angle2, segments [10])
love.graphics.arc(drawmode, arctype, x, y, radius, angle1, angle2, segments [10])
love.graphics.circle(mode, x, y, radius)
love.graphics.circle(mode, x, y, radius, segments)
love.graphics.clear()
love.graphics.clear(r, g, b, a [255])
love.graphics.clear(color, ...)
love.graphics.discard(discardcolor [true], discardstencil [true])
love.graphics.discard(discardcolors, discardstencil [true])
love.graphics.draw(drawable, x [0], y [0], r [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
love.graphics.draw(texture, quad, x [0], y [0], r [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
love.graphics.ellipse(mode, x, y, radiusx, radiusy)
love.graphics.ellipse(mode, x, y, radiusx, radiusy, segments)
love.graphics.intersectScissor(x, y, width, height)
love.graphics.intersectScissor()
love.graphics.line(x1, y1, x2, y2, ...)
love.graphics.line(points)
font = love.graphics.newFont(filename)
font = love.graphics.newFont(filename, size)
font = love.graphics.newFont(filename, imagefilename)
font = love.graphics.newFont(size)
mesh = love.graphics.newMesh(vertices, mode ["fan"], usage ["dynamic"])
mesh = love.graphics.newMesh(vertexcount, mode ["fan"], usage ["dynamic"])
mesh = love.graphics.newMesh(vertexformat, vertices, mode ["fan"], usage ["dynamic"])
mesh = love.graphics.newMesh(vertexformat, vertexcount, mode ["fan"], usage ["dynamic"])
image = love.graphics.newImage(filename)
image = love.graphics.newImage(imageData)
image = love.graphics.newImage(compressedImageData)
image = love.graphics.newImage(filename, flags)
font = love.graphics.newImageFont(filename, glyphs)
font = love.graphics.newImageFont(imageData, glyphs)
font = love.graphics.newImageFont(filename, glyphs, extraspacing [0])
shader = love.graphics.newShader(code)
shader = love.graphics.newShader(pixelcode, vertexcode)
video = love.graphics.newVideo(filename, loadaudio [nil])
video = love.graphics.newVideo(videostream, loadaudio [nil])
love.graphics.points(x, y, ...)
love.graphics.points(points)
love.graphics.points(points)
love.graphics.polygon(mode, ...)
love.graphics.polygon(mode, vertices)
love.graphics.print(text, x, y, r [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
love.graphics.print(coloredtext, x, y, angle [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
love.graphics.printf(text, x, y, limit, align ["left"], r [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
love.graphics.printf(coloredtext, x, y, wraplimit, align, angle [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
love.graphics.rectangle(mode, x, y, width, height)
love.graphics.rectangle(mode, x, y, width, height, rx, ry [rx], segments [nil])
love.graphics.setBackgroundColor(r, g, b, a [255])
love.graphics.setBackgroundColor(rgba)
love.graphics.setBlendMode(mode)
love.graphics.setBlendMode(mode, alphamode ["alphamultiply"])
love.graphics.setCanvas(canvas, ...)
love.graphics.setCanvas()
love.graphics.setCanvas(canvas1, canvas2, ...)
love.graphics.setColor(red, green, blue, alpha)
love.graphics.setColor(rgba)
love.graphics.setColorMask(red, green, blue, alpha)
love.graphics.setColorMask()
font = love.graphics.setNewFont(filename, size [12])
font = love.graphics.setNewFont(file, size [12])
font = love.graphics.setNewFont(data, size [12])
love.graphics.setShader()
love.graphics.setShader(shader)
love.graphics.setScissor(x, y, width, height)
love.graphics.setScissor()
love.graphics.setStencilTest(comparemode, comparevalue)
love.graphics.setStencilTest()
data = Canvas:newImageData()
data = Canvas:newImageData(x, y, width, height)
hasglyph = Font:hasGlyphs(character)
hasglyph = Font:hasGlyphs(codepoint)
attributecomponent, ... = Mesh:getVertex(index)
x, y, u, v, r, g, b, a = Mesh:getVertex(index)
Mesh:setDrawRange(min, max)
Mesh:setDrawRange()
Mesh:setTexture()
Mesh:setTexture(texture)
Mesh:setVertex(index, attributecomponent, ...)
Mesh:setVertex(index, vertex)
Mesh:setVertex(index, x, y, u, v, r [255], g [255], b [255], a [255])
Mesh:setVertex(index, vertex)
Mesh:setVertexMap(map)
Mesh:setVertexMap(vi1, vi2, vi3)
Mesh:setVertices(vertices)
Mesh:setVertices(vertices)
data = Image:getData()
data = Image:getData()
Image:refresh()
Image:refresh(x, y, width, height)
Image:setMipmapFilter(filtermode, sharpness [0])
Image:setMipmapFilter()
ParticleSystem:setQuads(quad1, quad2)
ParticleSystem:setQuads(quads)
Shader:send(name, number, ...)
Shader:send(name, vector, ...)
Shader:send(name, matrix, ...)
Shader:send(name, texture)
Shader:send(name, boolean, ...)
id = SpriteBatch:add(x, y, r [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
id = SpriteBatch:add(quad, x, y, r [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
SpriteBatch:set(id, x, y, r [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
SpriteBatch:set(id, quad, x, y, r [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
SpriteBatch:setColor(r, g, b, a [255])
SpriteBatch:setColor()
index = Text:add(textstring, x, y, angle [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
index = Text:add(coloredtext, x, y, angle [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
index = Text:addf(textstring, wraplimit, align, x, y, angle [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
index = Text:addf(coloredtext, wraplimit, align, x, y, angle [0], sx [1], sy [sx], ox [0], oy [0], kx [0], ky [0])
width, height = Text:getDimensions()
width, height = Text:getDimensions(index)
height = Text:getHeight()
height = Text:getHeight(index)
width = Text:getWidth()
width = Text:getWidth(index)
Text:set(textstring)
Text:set(coloredtext)
Text:set()
Text:setf(textstring, wraplimit, align ["left"])
Text:setf(coloredtext, wraplimit, align ["left"])
Text:setf()
compressed = love.image.isCompressed(filename)
compressed = love.image.isCompressed(fileData)
compressedImageData = love.image.newCompressedData(filename)
compressedImageData = love.image.newCompressedData(fileData)
imageData = love.image.newImageData(width, height)
imageData = love.image.newImageData(width, height, data)
imageData = love.image.newImageData(filename)
imageData = love.image.newImageData(filedata)
width, height = CompressedImageData:getDimensions()
width, height = CompressedImageData:getDimensions(level)
height = CompressedImageData:getHeight()
height = CompressedImageData:getHeight(level)
width = CompressedImageData:getWidth()
width = CompressedImageData:getWidth(level)
love.joystick.loadGamepadMappings(filename)
love.joystick.loadGamepadMappings(mappings)
mappings = love.joystick.saveGamepadMappings(filename)
mappings = love.joystick.saveGamepadMappings()
success = love.joystick.setGamepadMapping(guid, button, inputtype, inputindex, hatdirection)
success = love.joystick.setGamepadMapping(guid, axis, inputtype, inputindex, hatdirection)
inputtype, inputindex, hatdirection = Joystick:getGamepadMapping(axis)
inputtype, inputindex, hatdirection = Joystick:getGamepadMapping(button)
success = Joystick:setVibration(left, right)
success = Joystick:setVibration()
success = Joystick:setVibration(left, right, duration)
down = love.keyboard.isDown(key)
anyDown = love.keyboard.isDown(key, ...)
love.keyboard.setTextInput(enable)
love.keyboard.setTextInput(enable, x, y, w, h)
compressedData = love.math.compress(rawstring, format ["lz4"], level [-1])
compressedData = love.math.compress(data, format ["lz4"], level [-1])
rawstring = love.math.decompress(compressedData)
rawstring = love.math.decompress(compressedString, format)
rawstring = love.math.decompress(data, format)
lr, lg, lb = love.math.gammaToLinear(r, g, b)
lr, lg, lb = love.math.gammaToLinear(color)
lc = love.math.gammaToLinear(c)
convex = love.math.isConvex(vertices)
convex = love.math.isConvex(x1, y1, x2, y2, x3, y3, ...)
cr, cg, cb = love.math.linearToGamma(lr, lg, lb)
cr, cg, cb = love.math.linearToGamma(color)
c = love.math.linearToGamma(lc)
curve = love.math.newBezierCurve(vertices)
curve = love.math.newBezierCurve(x1, y1, x2, y2, x3, y3, ...)
rng = love.math.newRandomGenerator()
rng = love.math.newRandomGenerator(seed)
rng = love.math.newRandomGenerator(low, high)
value = love.math.noise(x)
value = love.math.noise(x, y)
value = love.math.noise(x, y, z)
value = love.math.noise(x, y, z, w)
number = love.math.random()
number = love.math.random(max)
number = love.math.random(min, max)
love.math.setRandomSeed(seed)
love.math.setRandomSeed(low, high)
triangles = love.math.triangulate(polygon)
triangles = love.math.triangulate(x1, y1, x2, y2, x3, y3, ...)
number = RandomGenerator:random()
number = RandomGenerator:random(max)
number = RandomGenerator:random(min, max)
RandomGenerator:setSeed(seed)
RandomGenerator:setSeed(low, high [0])
cursor = love.mouse.newCursor(imageData, hotx [0], hoty [0])
cursor = love.mouse.newCursor(filepath, hotx [0], hoty [0])
cursor = love.mouse.newCursor(fileData, hotx [0], hoty [0])
love.mouse.setCursor()
love.mouse.setCursor(cursor)
shape = love.physics.newChainShape(loop, x1, y1, x2, y2, ...)
shape = love.physics.newChainShape(loop, points)
shape = love.physics.newCircleShape(radius)
shape = love.physics.newCircleShape(x, y, radius)
joint = love.physics.newMotorJoint(body1, body2, correctionFactor [0.3])
joint = love.physics.newMotorJoint(body1, body2, correctionFactor [0.3], collideConnected [false])
shape = love.physics.newPolygonShape(x1, y1, x2, y2, ...)
shape = love.physics.newPolygonShape(vertices)
joint = love.physics.newPrismaticJoint(body1, body2, x, y, ax, ay, collideConnected [false])
joint = love.physics.newPrismaticJoint(body1, body2, x1, y1, x2, y2, ax, ay, collideConnected [false])
joint = love.physics.newPrismaticJoint(body1, body2, x1, y1, x2, y2, ax, ay, collideConnected [false], referenceAngle [0])
shape = love.physics.newRectangleShape(width, height)
shape = love.physics.newRectangleShape(x, y, width, height, angle [0])
joint = love.physics.newRevoluteJoint(body1, body2, x, y, collideConnected [false])
joint = love.physics.newRevoluteJoint(body1, body2, x1, y1, x2, y2, collideConnected [false], referenceAngle [0])
joint = love.physics.newWeldJoint(body1, body2, x, y, collideConnected [false])
joint = love.physics.newWeldJoint(body1, body2, x1, y1, x2, y2, collideConnected [false])
joint = love.physics.newWeldJoint(body1, body2, x1, y1, x2, y2, collideConnected [false], referenceAngle [0])
Body:applyForce(fx, fy)
Body:applyForce(fx, fy, x, y)
Body:applyLinearImpulse(ix, iy)
Body:applyLinearImpulse(ix, iy, x, y)
decoder = love.sound.newDecoder(file, buffer [2048])
decoder = love.sound.newDecoder(filename, buffer [2048])
soundData = love.sound.newSoundData(filename)
soundData = love.sound.newSoundData(file)
soundData = love.sound.newSoundData(data)
soundData = love.sound.newSoundData(samples, rate [44100], bits [16], channels [2])
thread = love.thread.newThread(filename)
thread = love.thread.newThread(fileData)
thread = love.thread.newThread(codestring)
Thread:start()
Thread:start(arg1, arg2, ...)
videostream = love.video.newVideoStream(filename)
videostream = love.video.newVideoStream(file)
value = love.window.fromPixels(pixelvalue)
x, y = love.window.fromPixels(px, py)
success = love.window.setFullscreen(fullscreen)
success = love.window.setFullscreen(fullscreen, fstype)
success = love.window.showMessageBox(title, message, type ["info"], attachtowindow [true])
pressedbutton = love.window.showMessageBox(title, message, buttonlist, type ["info"], attachtowindow [true])
pixelvalue = love.window.toPixels(value)
px, py = love.window.toPixels(x, y)
@pablomayobre
Copy link
Collaborator

This would actually be pretty cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants