summaryrefslogtreecommitdiff
path: root/Examples
diff options
context:
space:
mode:
authorMark Gossage <mark@gossage.cjb.net>2007-01-22 04:59:16 +0000
committerMark Gossage <mark@gossage.cjb.net>2007-01-22 04:59:16 +0000
commita997938b638a8b9fcac1b8a0d5674fda210734ef (patch)
tree948d57da94b0ade035ecb1632a348ae8d030a5bc /Examples
parent5d0c155688e2d8bba41f7113d5316334a91aa5b7 (diff)
downloadswig-a997938b638a8b9fcac1b8a0d5674fda210734ef.tar.gz
Added a lua specific carrays.i which adds the operator[] support.
modified the main code to make it not emit all the class member functions & accessors git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9642 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples')
-rw-r--r--Examples/lua/functor/runme.lua4
-rw-r--r--Examples/test-suite/lua/li_carrays_runme.lua29
2 files changed, 31 insertions, 2 deletions
diff --git a/Examples/lua/functor/runme.lua b/Examples/lua/functor/runme.lua
index 03d299e9f..e0e44c129 100644
--- a/Examples/lua/functor/runme.lua
+++ b/Examples/lua/functor/runme.lua
@@ -19,6 +19,6 @@ for i=0,100 do
a(i) -- Note: function call
b(math.sqrt(i)) -- Note: function call
end
-print(a:result()) -- should be 5050
-print(b:result()) -- should be ~771.46
+print("int sum 0..100 is",a:result(),"(expected 5050")
+print("double sum 0..100 is",b:result(),"(expected ~771.46)")
diff --git a/Examples/test-suite/lua/li_carrays_runme.lua b/Examples/test-suite/lua/li_carrays_runme.lua
new file mode 100644
index 000000000..c54e36acc
--- /dev/null
+++ b/Examples/test-suite/lua/li_carrays_runme.lua
@@ -0,0 +1,29 @@
+require("import") -- the import fn
+import("li_carrays") -- import code
+
+-- moving to global
+for k,v in pairs(li_carrays) do _G[k]=v end
+
+-- catch "undefined" global variables
+setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
+
+-- Testing for %array_functions(int,intArray)
+ary = new_intArray(2)
+intArray_setitem(ary, 0, 0)
+intArray_setitem(ary, 1, 1)
+assert(intArray_getitem(ary, 0)==0)
+assert(intArray_getitem(ary, 1)==1)
+delete_intArray(ary)
+
+-- Testing for %array_class(double, doubleArray)
+d = doubleArray(10)
+d[0] = 7
+d[5] = d[0] + 3
+assert(d[5] + d[0] == 17)
+--print(d[5] + d[0])
+
+ptr = d:cast() -- to ptr
+d2 = doubleArray_frompointer(ptr) -- and back to array
+assert(d2[5] + d2[0] == 17)
+--print(d2[5] + d2[0])
+