Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file: -- http://angg.twu.net/LUA/vector-demo.lua.html -- http://angg.twu.net/LUA/vector-demo.lua -- (find-angg "LUA/vector-demo.lua") -- Author: Eduardo Ochs <eduardoochs@gmail.com> Class = { type = "Class", __call = function (class, o) return setmetatable(o, class) end, } setmetatable(Class, Class) Vector = Class { type = "Vector", __add = function (V, W) return Vector {V[1]+W[1], V[2]+W[2]} end, __tostring = function (V) return "("..V[1]..","..V[2]..")" end, __index = { norm = function (V) return math.sqrt(V[1]^2 + V[2]^2) end, }, } --[[ * (eepitch-lua51) * (eepitch-kill) * (eepitch-lua51) dofile "vector-demo.lua" v = Vector {3, 4} -- v = { 3, 4, __mt = Vector} w = Vector {20, 30} -- w = {20, 30, __mt = Vector} print(v) --> (3,4) print(v + w) --> (23,34) print(v:norm()) --> 5 print( type(v)) --> table print(otype(v)) --> Vector print( type("")) --> string print(otype("")) --> string --]] -- Local Variables: -- coding: utf-8-unix -- End: