2013-03-05 16:57:55 +01:00
|
|
|
--[[--------
|
|
|
|
A simple module with examples.
|
|
|
|
|
2013-03-08 12:40:59 +01:00
|
|
|
Even without markdown formatting, blank lines are respected.
|
|
|
|
|
2013-03-05 16:57:55 +01:00
|
|
|
@module usage
|
|
|
|
]]
|
|
|
|
|
|
|
|
local usage = {}
|
|
|
|
|
2013-03-07 12:49:39 +01:00
|
|
|
local helper
|
|
|
|
|
|
|
|
--- a local helper function.
|
|
|
|
-- @local
|
|
|
|
function helper ()
|
|
|
|
end
|
|
|
|
|
2013-03-05 16:57:55 +01:00
|
|
|
----------
|
2013-03-07 12:09:48 +01:00
|
|
|
-- A simple vector class.
|
|
|
|
--
|
|
|
|
-- Supports arithmetic operations.
|
|
|
|
-- @usage
|
|
|
|
-- v = Vector.new {10,20,30}
|
|
|
|
-- assert (v == Vector{10,20,30})
|
2013-03-05 16:57:55 +01:00
|
|
|
-- @type Vector
|
|
|
|
|
|
|
|
local Vector = {}
|
|
|
|
usage.Vector = {}
|
|
|
|
|
2013-03-07 12:49:39 +01:00
|
|
|
|
2013-03-05 16:57:55 +01:00
|
|
|
----------
|
|
|
|
-- Create a vector from an array `t`.
|
2013-03-07 12:09:48 +01:00
|
|
|
-- `Vector` is also callable!
|
2013-03-05 16:57:55 +01:00
|
|
|
function Vector.new (t)
|
|
|
|
end
|
|
|
|
|
2013-03-07 12:39:41 +01:00
|
|
|
-- note that @function may have modifiers. Currently
|
|
|
|
-- we aren't doing anything with them, but LDoc no longer
|
|
|
|
-- complains (issue #45). Note also that one needs
|
|
|
|
-- explicit @param tags with explicit @function; 'static'
|
|
|
|
-- methods must have a @constructor or a @static tag.
|
|
|
|
|
2013-03-05 16:57:55 +01:00
|
|
|
----------
|
|
|
|
-- Create a vector from a string.
|
|
|
|
-- @usage
|
|
|
|
-- v = Vector.parse '[1,2,3]'
|
|
|
|
-- assert (v == Vector.new {1,2,3})
|
2013-03-07 12:39:41 +01:00
|
|
|
-- @function[kind=ctor] parse
|
|
|
|
-- @static
|
|
|
|
-- @param s
|
2013-03-05 16:57:55 +01:00
|
|
|
function Vector.parse (s)
|
|
|
|
end
|
|
|
|
|
2013-03-07 12:09:48 +01:00
|
|
|
--------
|
|
|
|
-- Compare two vectors for equality.
|
|
|
|
function Vector:__eq (v)
|
|
|
|
end
|
|
|
|
|
2013-03-05 16:57:55 +01:00
|
|
|
----------
|
|
|
|
-- Add another vector, array or scalar `v` to this vector.
|
|
|
|
-- Returns new `Vector`
|
|
|
|
-- @usage assert(Vector.new{1,2,3}:add(1) == Vector{2,3,4})
|
|
|
|
function Vector:add (v)
|
|
|
|
end
|
|
|
|
|
2013-03-08 12:40:59 +01:00
|
|
|
----------
|
|
|
|
-- set vector options. `opts` is a `Vector.Opts` table.
|
|
|
|
function Vector:options (opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[-----------------
|
|
|
|
@table Vector.Opts
|
2013-05-15 15:30:47 +02:00
|
|
|
Options table format for `Vector:options`
|
2013-03-08 12:40:59 +01:00
|
|
|
|
2013-05-15 15:30:47 +02:00
|
|
|
* `autoconvert`: try to convert strings to numbers
|
|
|
|
* `adder`: function used to perform addition and subtraction
|
|
|
|
* `multiplier`: function used to perform multiplication and division
|
2013-03-08 12:40:59 +01:00
|
|
|
|
|
|
|
@usage
|
|
|
|
v = Vector {{1},{2}}
|
|
|
|
v:options {adder = function(x,y) return {x[1]+y[1]} end}
|
|
|
|
assert(v:add(1) == Vector{{2},{3}})
|
|
|
|
]]
|
|
|
|
|
2013-03-05 16:57:55 +01:00
|
|
|
return usage
|
|
|
|
|
|
|
|
|