summaryrefslogtreecommitdiff
path: root/Examples/lua/import/runme.lua
blob: 7057b7bbd8c8549520426d884d6f337c1207d93f (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Test various properties of classes defined in separate modules

print("Testing the %import directive")

if string.sub(_VERSION,1,7)=='Lua 5.0' then
	-- lua5.0 doesn't have a nice way to do this
	function loadit(a)
		lib=loadlib(a..'.dll','luaopen_'..a) or loadlib(a..'.so','luaopen_'..a)
		assert(lib)()
	end
	loadit('base')
	loadit('foo')
	loadit('bar')
	loadit('spam')
else
	-- lua 5.1 does
	require 'base'
	require 'foo'
	require 'bar'
	require 'spam'
end

-- Create some objects

print("Creating some objects")

a = base.Base()
b = foo.Foo()
c = bar.Bar()
d = spam.Spam()

-- Try calling some methods
print("Testing some methods")
print("Should see 'Base::A' ---> ",a:A())
print("Should see 'Base::B' ---> ",a:B())

print("Should see 'Foo::A' ---> ",b:A())
print("Should see 'Foo::B' ---> ",b:B())

print("Should see 'Bar::A' ---> ",c:A())
print("Should see 'Bar::B' ---> ",c:B())

print("Should see 'Spam::A' ---> ",d:A())
print("Should see 'Spam::B' ---> ",d:B())

-- Try some casts

print("\nTesting some casts")

x = a:toBase()
print("Should see 'Base::A' ---> ",x:A())
print("Should see 'Base::B' ---> ",x:B())

x = b:toBase()
print("Should see 'Foo::A' ---> ",x:A())
print("Should see 'Base::B' ---> ",x:B())

x = c:toBase()
print("Should see 'Bar::A' ---> ",x:A())
print("Should see 'Base::B' ---> ",x:B())

x = d:toBase()
print("Should see 'Spam::A' ---> ",x:A())
print("Should see 'Base::B' ---> ",x:B())

x = d:toBar()
print("Should see 'Bar::B' ---> ",x:B())


print "\nTesting some dynamic casts\n"
x = d:toBase()

print " Spam -> Base -> Foo : "
y = foo.Foo_fromBase(x)
if y then
      print "bad swig"
else
      print "good swig"
end

print " Spam -> Base -> Bar : "
y = bar.Bar_fromBase(x)
if y then
      print "good swig"
else
      print "bad swig"
end
      
print " Spam -> Base -> Spam : "
y = spam.Spam_fromBase(x)
if y then
      print "good swig"
else
      print "bad swig"
end

print " Foo -> Spam : "
y = spam.Spam_fromBase(b)
if y then
      print "bad swig"
else
      print "good swig"
end