PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/lua/pointer/runme.lua

#
Lua | 48 lines | 27 code | 9 blank | 12 comment | 1 complexity | 8d90a53d1fe5df43f9b66795d42c280f MD5 | raw file
 1---- importing ----
 2if string.sub(_VERSION,1,7)=='Lua 5.0' then
 3	-- lua5.0 doesnt have a nice way to do this
 4	lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
 5	assert(lib)()
 6else
 7	-- lua 5.1 does
 8	require('example')
 9end
10
11-- First create some objects using the pointer library.
12print("Testing the pointer library")
13a = example.new_intp()
14b = example.new_intp()
15c = example.new_intp()
16example.intp_assign(a,37)
17example.intp_assign(b,42)
18
19print("     a = "..tostring(a))
20print("     b = "..tostring(b))
21print("     c = "..tostring(c))
22
23-- Call the add() function with some pointers
24example.add(a,b,c)
25
26-- Now get the result
27r = example.intp_value(c)
28print("     37 + 42 = "..r)
29
30-- Clean up the pointers
31-- since this is C-style pointers you must clean it up
32example.delete_intp(a)
33example.delete_intp(b)
34example.delete_intp(c)
35
36-- Now try the typemap library
37-- This should be much easier. Now how it is no longer
38-- necessary to manufacture pointers.
39
40print("Trying the typemap library")
41r = example.sub(37,42)
42print("     37 - 42 = "..r)
43
44-- Now try the version with multiple return values
45
46print("Testing multiple return values")
47q,r = example.divide(42,37)
48print("     42/37 = "..q.." remainder "..r)