File: runme.lua

package info (click to toggle)
renderdoc 1.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 79,584 kB
  • sloc: cpp: 491,671; ansic: 285,823; python: 12,617; java: 11,345; cs: 7,181; makefile: 6,703; yacc: 5,682; ruby: 4,648; perl: 3,461; php: 2,119; sh: 2,068; lisp: 1,835; tcl: 1,068; ml: 747; xml: 137
file content (54 lines) | stat: -rw-r--r-- 1,428 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---- importing ----
if string.sub(_VERSION,1,7)=='Lua 5.0' then
	-- lua5.0 doesnt have a nice way to do this
	lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
	assert(lib)()
else
	-- lua 5.1 does
	require('example')
end

a = 37
b = 42

-- Now call our C function

print("Trying some C functions")
print("    a        =", a)
print("    b        =", b)
print("    add(a,b) =", example.add(a,b))
print("    sub(a,b) =", example.sub(a,b))
print("    mul(a,b) =", example.mul(a,b))

print("Calling them using the my_func()")
print("    add(a,b) =", example.callback(a,b,example.add))
print("    sub(a,b) =", example.callback(a,b,example.sub))
print("    mul(a,b) =", example.callback(a,b,example.mul))

print("Now let us write our own function")
function foo(a,b) return 101 end
print("    foo(a,b) =", example.callback(a,b,foo))

print("Now let us try something that will fail")
local ok,c=pcall(example.callback,a,b,print)
if ok==false then
	print("this failed as expected, error:",c)
else
	print("oops, that worked! result:",c)
end


-- part2 stored function
print("trying a stored fn")
print("the_func=",example.the_func)
print("setting to print")
example.the_func=print
print("the_func=",example.the_func)
print("call_the_func(5)")
example.call_the_func(5)

function bar(i) print("bar",i) end
print("setting to bar")
example.the_func=bar
print("call_the_func(5)")
example.call_the_func(5)