99
1010function on_event ()
1111
12- print (entity )
13- print (script )
14- print (world )
12+ world :spawn ()
1513
14+ world :exit ()
1615
17- local my_component_type = world :get_type_by_name (" MyComponent" )
16+ -- print(entity)
17+ -- print(script)
18+ -- print(world)
1819
19- local comp = world :get_component (entity , my_component_type )
20- print (" Before script: " , comp )
2120
22- print (" \n option" )
23- print (comp .option_usize )
24- comp .option_usize = 69
25- print (comp .option_usize )
26- comp .option_usize = nil
27- print (comp .option_usize )
21+ -- local my_component_type = world:get_type_by_name("MyComponent")
2822
29- print (" \n vec" )
30- print (table_to_string (comp .vec_of_usize ))
31- comp .vec_of_usize = {42 ,69 ,72 }
32- comp .vec_of_usize [1 ] = 0
33- print (comp .vec_of_usize [2 ])
34- print (table_to_string (comp .vec_of_usize ))
35- comp .vec_of_usize = {}
36- print (table_to_string (comp .vec_of_usize ))
37- comp .vec_of_usize = comp .vec_of_usize2
38- print (table_to_string (comp .vec_of_usize ))
39- comp .vec_of_usize = comp .vec_of_usize
40- print (table_to_string (comp .vec_of_usize ))
41- comp .vec_of_usize :insert (1 , 42 )
42- print (table_to_string (comp .vec_of_usize ))
23+ -- local comp = world:get_component(entity, my_component_type)
24+ -- print("Before script: ", comp)
4325
44- print (" \n map" )
45- -- print(comp.map_of_strings["key"])
46- comp .map_of_strings :insert (" key2" , " value" )
47- -- print(comp.map_of_strings["key2"])
26+ -- print("\noption")
27+ -- print(comp.option_usize)
28+ -- comp.option_usize = 69
29+ -- print(comp.option_usize)
30+ -- comp.option_usize = nil
31+ -- print(comp.option_usize)
4832
33+ -- print("\nvec")
34+ -- print(table_to_string(comp.vec_of_usize))
35+ -- comp.vec_of_usize = {42,69,72}
36+ -- comp.vec_of_usize[1] = 0
37+ -- print(comp.vec_of_usize[2])
38+ -- print(table_to_string(comp.vec_of_usize))
39+ -- comp.vec_of_usize = {}
40+ -- print(table_to_string(comp.vec_of_usize))
41+ -- comp.vec_of_usize = comp.vec_of_usize2
42+ -- print(table_to_string(comp.vec_of_usize))
43+ -- comp.vec_of_usize = comp.vec_of_usize
44+ -- print(table_to_string(comp.vec_of_usize))
45+ -- comp.vec_of_usize:insert(1, 42)
46+ -- print(table_to_string(comp.vec_of_usize))
4947
48+ -- print("\nmap")
49+ -- -- print(comp.map_of_strings["key"])
50+ -- comp.map_of_strings:insert("key2", "value")
51+ -- -- print(comp.map_of_strings["key2"])
5052
51- print (" ============" )
5253
53- -- vec's and matrices have custom __index and __newindex overrides
54- print (" comp.vec2 before: " , comp .vec2 )
55- comp .vec2 [1 ] = 69
56- print (" comp.vec2 after: " , comp .vec2 )
5754
58- -- Option's get converted to nil or the value inside
59- print (" comp.option_vec3 before: " , comp .option_vec3 )
60- comp .option_vec3 = Vec3 .new (2 ,1 ,3 )
61- print (" comp.option_vec3 after: " , comp .option_vec3 )
55+ -- print("============")
6256
63- -- reflection via index is indexed starting at 1, unlike in Rust to match Lua's indexing
64- print (" comp.option_vec3[1] before: " , comp .option_vec3 [ 1 ] )
65- comp .option_vec3 [1 ] = 5
66- print (" comp.option_vec3[1] after: " , comp .option_vec3 [ 1 ] )
57+ -- -- vec's and matrices have custom __index and __newindex overrides
58+ -- print("comp.vec2 before: ", comp.vec2 )
59+ -- comp.vec2 [1] = 69
60+ -- print("comp.vec2 after: ", comp.vec2 )
6761
68- print (" ============" )
62+ -- -- Option's get converted to nil or the value inside
63+ -- print("comp.option_vec3 before: ", comp.option_vec3)
64+ -- comp.option_vec3 = Vec3.new(2,1,3)
65+ -- print("comp.option_vec3 after: ", comp.option_vec3)
6966
70- -- Vec<T> references get converted to a custom proxy `LuaVec<T>` which is
71- -- also assignable via lua tables
67+ -- -- reflection via index is indexed starting at 1, unlike in Rust to match Lua's indexing
68+ -- print("comp.option_vec3[1] before: ", comp.option_vec3[1])
69+ -- comp.option_vec3[1] = 5
70+ -- print("comp.option_vec3[1] after: ", comp.option_vec3[1])
7271
73- print (" comp.vec_of_option_bools before: " , table_to_string (comp .vec_of_option_bools ))
74- comp .vec_of_option_bools = {true ,false ,true }
75- print (" comp.vec_of_option_bools after assignment: " , table_to_string (comp .vec_of_option_bools ))
72+ -- print("============")
7673
77- print (" comp.vec_of_option_bools[1] before: " , comp .vec_of_option_bools [1 ])
78- comp .vec_of_option_bools [1 ] = false
79- print (" comp.vec_of_option_bools[1] after: " , comp .vec_of_option_bools [1 ])
74+ -- -- Vec<T> references get converted to a custom proxy `LuaVec<T>` which is
75+ -- -- also assignable via lua tables
8076
81- -- there are some additional methods available on LuaVec proxies imitating the Vec<T> api
82- print (" comp.vec_of_option_bools before insert: " , table_to_string (comp .vec_of_option_bools ))
83- comp .vec_of_option_bools :insert (1 ,nil )
84- print (" comp.vec_of_option_bools after insert: " , table_to_string (comp .vec_of_option_bools ))
77+ -- print("comp.vec_of_option_bools before: ", table_to_string(comp.vec_of_option_bools))
78+ -- comp.vec_of_option_bools = {true,false,true}
79+ -- print("comp.vec_of_option_bools after assignment: ", table_to_string(comp.vec_of_option_bools))
8580
81+ -- print("comp.vec_of_option_bools[1] before: ", comp.vec_of_option_bools[1])
82+ -- comp.vec_of_option_bools[1] = false
83+ -- print("comp.vec_of_option_bools[1] after: ", comp.vec_of_option_bools[1])
8684
85+ -- -- there are some additional methods available on LuaVec proxies imitating the Vec<T> api
86+ -- print("comp.vec_of_option_bools before insert: ", table_to_string(comp.vec_of_option_bools))
87+ -- comp.vec_of_option_bools:insert(1,nil)
88+ -- print("comp.vec_of_option_bools after insert: ", table_to_string(comp.vec_of_option_bools))
8789
88- print (" comp.vec_of_option_bools before push: " , table_to_string (comp .vec_of_option_bools ))
89- comp .vec_of_option_bools :push (false )
90- print (" comp.vec_of_option_bools after push: " , table_to_string (comp .vec_of_option_bools ))
9190
92- print (" comp.vec_of_option_bools len after push: " , # comp .vec_of_option_bools )
9391
94- print (" comp.vec_of_option_bools before pop : " , table_to_string (comp .vec_of_option_bools ))
95- print ( comp .vec_of_option_bools :pop (): print_value () )
96- print (" comp.vec_of_option_bools after pop : " , table_to_string (comp .vec_of_option_bools ))
92+ -- print("comp.vec_of_option_bools before push : ", table_to_string(comp.vec_of_option_bools))
93+ -- comp.vec_of_option_bools:push(false )
94+ -- print("comp.vec_of_option_bools after push : ", table_to_string(comp.vec_of_option_bools))
9795
98- print (" the pairs inside comp.vec_of_option_bools: " )
99- for k ,v in pairs (comp .vec_of_option_bools ) do
100- print (string.format (" - %s:%s" ,k ,v ))
101- end
96+ -- print("comp.vec_of_option_bools len after push: ", #comp.vec_of_option_bools)
97+
98+ -- print("comp.vec_of_option_bools before pop: ", table_to_string(comp.vec_of_option_bools))
99+ -- print(comp.vec_of_option_bools:pop():print_value())
100+ -- print("comp.vec_of_option_bools after pop: ", table_to_string(comp.vec_of_option_bools))
102101
102+ -- print("the pairs inside comp.vec_of_option_bools: ")
103+ -- for k,v in pairs(comp.vec_of_option_bools) do
104+ -- print(string.format(" - %s:%s",k,v))
105+ -- end
103106
104- comp .vec_of_option_bools :clear ()
105- print (" comp.vec_of_option_bools after clear: " , table_to_string (comp .vec_of_option_bools ))
106- print (" comp.vec_of_option_bools len after clear: " , # comp .vec_of_option_bools )
107107
108- print (" ============" )
108+ -- comp.vec_of_option_bools:clear()
109+ -- print("comp.vec_of_option_bools after clear: ", table_to_string(comp.vec_of_option_bools))
110+ -- print("comp.vec_of_option_bools len after clear: ", #comp.vec_of_option_bools)
109111
110- print (Vec3 .new (0 ,1 ,0 ) + Vec3 .new (1 ,0 ,0 ))
111- print (Vec3 .new (0 ,1 ,0 ):any_orthonormal_vector ())
112- print (comp .mat3 [1 ])
113- print (Vec3 .new (0 ,1 ,0 ):any_orthonormal_vector () + comp .mat3 [1 ])
114- local complex_vec_op = Vec3 .new (0 ,1 ,0 ):any_orthonormal_vector () + comp .mat3 [1 ]
115- print (" (0,1,0).any_orthonormal_vector() + mat3.x_axis is: " , complex_vec_op )
112+ -- print("============")
116113
117- local new_mat3 = Mat3 .from_cols (Vec3 .new (1 ,0 ,0 ),Vec3 .new (0 ,1 ,0 ),Vec3 .new (0 ,0 ,- 1 ))
118- print (" new_mat3 is:" , new_mat3 )
114+ -- print(Vec3.new(0,1,0) + Vec3.new(1,0,0))
115+ -- print(Vec3.new(0,1,0):any_orthonormal_vector())
116+ -- print(comp.mat3[1])
117+ -- print(Vec3.new(0,1,0):any_orthonormal_vector() + comp.mat3[1])
118+ -- local complex_vec_op = Vec3.new(0,1,0):any_orthonormal_vector() + comp.mat3[1]
119+ -- print("(0,1,0).any_orthonormal_vector() + mat3.x_axis is: ", complex_vec_op)
120+
121+ -- local new_mat3 = Mat3.from_cols(Vec3.new(1,0,0),Vec3.new(0,1,0),Vec3.new(0,0,-1))
122+ -- print("new_mat3 is:", new_mat3)
119123
120- comp .vec2 = comp .vec2 + comp .vec2
121- print (" A" )
122- comp .usize = comp .vec2 :min_element ()
124+ -- comp.vec2 = comp.vec2 + comp.vec2
125+ -- print("A")
126+ -- comp.usize = comp.vec2:min_element()
123127
124- print (" B" )
125- comp .f32 = comp .f32 + comp .f32 + comp .vec2 :min_element ()
126- print (" C" )
127- comp .vec2 = Vec2 .new (2 ,1 )
128- print (" D" )
129- comp .quat = Quat .from_xyzw (3 ,2 ,1 ,4 )
130- print (" E" )
131- comp .mat3 [1 ] = Vec3 .new (69 ,69 ,69 )
132- print (" F" )
128+ -- print("B")
129+ -- comp.f32 = comp.f32 + comp.f32 + comp.vec2:min_element()
130+ -- print("C")
131+ -- comp.vec2 = Vec2.new(2,1)
132+ -- print("D")
133+ -- comp.quat = Quat.from_xyzw(3,2,1,4)
134+ -- print("E")
135+ -- comp.mat3[1] = Vec3.new(69,69,69)
136+ -- print("F")
133137
134138
135- world :exit ()
136- do return end
137- print (" ============" )
139+ -- world:exit()
140+ -- do return end
141+ -- print("============")
138142
139- -- this is an example of something impossible to achieve with plain bevy reflection under the hood
140- comp .mat3 [1 ][1 ] = 42
143+ -- -- this is an example of something impossible to achieve with plain bevy reflection under the hood
144+ -- comp.mat3[1][1] = 42
141145
142- -- now let's retrieve these again to see if we actually changed their values permanently
143- comp = world :get_component (entity ,my_component_type )
146+ -- -- now let's retrieve these again to see if we actually changed their values permanently
147+ -- comp = world:get_component(entity,my_component_type)
144148
145- print (" After script:" )
146- print (comp )
149+ -- print("After script:")
150+ -- print(comp)
147151
148- world :exit ()
152+ -- world:exit()
149153end
0 commit comments