-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.lua
More file actions
58 lines (48 loc) · 1.12 KB
/
Copy pathtest.lua
File metadata and controls
58 lines (48 loc) · 1.12 KB
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
55
56
57
58
-- for c++ function call
function main()
print("start")
local a = newA()
a:set_int(123)
print("a:get_int() ", a:get_int())
assert(a:get_int() == 123, "get_int mismatch")
assert(a:get_int_const() == 123, "get_int_const mismatch")
a:set_string("abc")
print("a:set_string() ", a:get_string())
assert(a:get_string() == "abc", "get_string mismatch")
printA(a)
local aa = a:get_this()
print("aa == a ", aa == a)
assert(aa == a, "pointer identity mismatch")
printA(aa)
print("done")
end
-- for global lua function call
function benchmark(n, log)
local begin = os.time()
local a = newA()
local sum = 0
for i = 1, n do
a:get_int()
a:set_int(i)
sum = sum + i
end
local cost = os.time() - begin
print(cost, log, sum)
printA(a)
return cost, log, sum, a
end
-- for 0-arg lua function call test
function zero_arg_func()
return 42
end
-- for table lua function call
_G.test = {}
_G.test.func = {}
function _G.test.func.test(a, b)
return a - b
end
local ok, err = pcall(main)
if not ok then
print(err)
error(err)
end