-
Notifications
You must be signed in to change notification settings - Fork 23
/
function.py
61 lines (42 loc) · 1.12 KB
/
function.py
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
59
60
61
import upywraptest
import math
def func1():
print('func1')
def func1gen(a):
def fn():
print(a)
return fn
upywraptest.Func1(func1)
upywraptest.Func1(func1gen('func1'))
upywraptest.Func1(lambda: print('func1'))
# Special case because it will pass around the std::function
# directly, see FromPyObj< std::function >, but there's no way
# to test that specifically.
upywraptest.Func1(upywraptest.ToFunc1())
def func2(a):
print(a)
upywraptest.Func2(func2)
def func3():
return 3
upywraptest.Func3(func3)
def func4(i, s):
return '{}{}'.format(i, s)
upywraptest.Func4(func4)
# native functions
upywraptest.Func5(math.fabs)
upywraptest.Func5(upywraptest.Func6)
# more than 3 arguments
def Take4(a, b, c, d):
return a + b + c + d
print(upywraptest.Func8(upywraptest.Func7))
print(upywraptest.Func8(Take4))
print(upywraptest.IsEmptyFunction(None))
def ModifyNative(s):
s.val = 45
print(upywraptest.CallbackWithNativeArg(ModifyNative))
print(upywraptest.NoFunc())
upywraptest.ToFunc1()()
print(upywraptest.ToFunc2()(upywraptest.Simple(33)))
isEmpty = upywraptest.ToFunc3()
print(isEmpty(None))
print(isEmpty(lambda: 0))