1
-- demo of lua swig capacilities (operator overloading)
2
require("import") -- the import fn
3
import("operator_overload") -- import lib
5
for k,v in pairs(operator_overload) do _G[k]=v end -- move to global
7
-- catching undefined variables
8
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
13
c=Op(b) -- copy construct
15
dd=d; -- assignment operator
31
-- lua does not support += operators: skiping
40
--assert(f%g==Op(0)) -- lua does not support %
42
-- test unary operators
43
--assert((not a)==true) -- lua does not allow overloading for not operator
44
--assert((not b)==false) -- lua does not allow overloading for not operator
64
-- plus add some code to check the __str__ fn
65
assert(tostring(Op(1))=="Op(1)")
66
assert(tostring(Op(-3))=="Op(-3)")
69
/* Sample test code in C++
74
int main(int argc,char** argv)
79
Op c=b; // copy construct
117
// test unary operators
139
// plus add some code to check the __str__ fn
140
//assert(str(Op(1))=="Op(1)");
141
//assert(str(Op(-3))=="Op(-3)");