2013-03-05 16:57:55 +01:00
|
|
|
--[[--------
|
|
|
|
A simple module with examples.
|
|
|
|
|
|
|
|
@module usage
|
|
|
|
]]
|
|
|
|
|
|
|
|
local usage = {}
|
|
|
|
|
|
|
|
----------
|
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 = {}
|
|
|
|
|
|
|
|
----------
|
|
|
|
-- 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
|
|
|
|
|
|
|
|
----------
|
|
|
|
-- Create a vector from a string.
|
|
|
|
-- @usage
|
|
|
|
-- v = Vector.parse '[1,2,3]'
|
|
|
|
-- assert (v == Vector.new {1,2,3})
|
|
|
|
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
|
|
|
|
|
|
|
|
return usage
|
|
|
|
|
|
|
|
|