[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: luaSDL & Lua 5.0: Patches and a small SDL_Event type problem
- From: "Vbr. Andre Kloss" <kloss@...>
- Date: Sat, 27 Dec 2003 16:14:23 +0100
Hi folks.
I managed to get luaSDL compiled and running with Linux 2.4, gcc 3.3.1, Lua 5.0,
SDL 1.2.6 and tolua 5.0 alpha. I encountered a small problem with variables
of the same name but different classes: The getter and setter functions get
the same C function name, and C balks at the ambiguity.
The attached variable.patch fixed the problem for me, the array.patch should do
the same for arrays (but I did not have that problem, therefore I have split
the patches). The sample game, meteor_shower.lua runs when changing
loadmodule to loadlib, tag functions to metatables and giving utility
functions like getn their correct namespace, e.g. table.getn - the
meteor_shower.patch includes this changes.
One problem remains: The SDL_Poll_Event function returns a
SDL_Keyboard_Event instead of a SDL_Event when a key is pressed. Since
SDL_Event is a union, every SDL_Event *could* be a SDL_Keyboard_Event,
or any other member of the union.
The first symptom of this problem is (compiled without RELEASE), the
program exits on key press, reporting the alleged type mismatch.
Compiled with CFLAGS=-DRELEASE=1, it stops on event.key.keysym, because the
event is already the SDL_Keyboard_Event. Changing this to event.keysym gets
rid of the symptoms.
However, I am not happy with this workaround, as it shows two problems:
- tolua type checking is too rigid (it should accept all members of a
union type, IMHO - prove me wrong...)
- There may be some problem with SDL or luaSDL. I have not found a
reference in the SDL changelogs to whether the SDL_Event interfaces
have changed, but if this is the case, luaSDL should probably upgrade
to match the new interfaces?
Happy new year!
Andre
--
Tolerance rulez, everything else sux! -- Andre Kloss
--- variable.lua Fri Aug 1 23:19:00 2003
+++ ../../../../variable.lua Mon Dec 22 09:05:40 2003
@@ -93,10 +93,11 @@
-- get function ------------------------------------------------
if class then
output("/* get function:",self.name," of class ",class," */")
+ self.cgetname = self:cfuncname("tolua_get_"..class)
else
output("/* get function:",self.name," */")
+ self.cgetname = self:cfuncname("tolua_get")
end
- self.cgetname = self:cfuncname("tolua_get")
output("static int",self.cgetname,"(lua_State* tolua_S)")
output("{")
@@ -138,10 +139,11 @@
if not strfind(self.type,'const') then
if class then
output("/* set function:",self.name," of class ",class," */")
+ self.csetname = self:cfuncname("tolua_set_"..class)
else
output("/* set function:",self.name," */")
+ self.csetname = self:cfuncname("tolua_set")
end
- self.csetname = self:cfuncname("tolua_set")
output("static int",self.csetname,"(lua_State* tolua_S)")
output("{")
--- array.lua Wed Jul 30 20:07:41 2003
+++ ../../../../array.lua Mon Dec 22 09:05:48 2003
@@ -55,10 +55,11 @@
-- get function ------------------------------------------------
if class then
output("/* get function:",self.name," of class ",class," */")
+ self.cgetname = self:cfuncname("tolua_get_"..class)
else
output("/* get function:",self.name," */")
+ self.cgetname = self:cfuncname("tolua_get")
end
- self.cgetname = self:cfuncname("tolua_get")
output("static int",self.cgetname,"(lua_State* tolua_S)")
output("{")
output(" int tolua_index;")
10,11c10,11
< if loadmodule then
< loadmodule("SDL")
---
> if loadlib then
> assert(loadlib("libluaSDL.so", "tolua_SDL_open"))()
76c76,105
< vec2_tag = nil -- be sure to re-init the vector type if we reload
---
> --vec2_tag = nil -- be sure to re-init the vector type if we reload
>
> vec2_meta = { }
> function vec2_meta.__add(a, b) return vec2{ a.x + b.x, a.y + b.y } end
> function vec2_meta.__sub(a, b) return vec2{ a.x - b.x, a.y - b.y } end
> function vec2_meta.__mul(a, b)
> if (tonumber(a)) then
> return vec2{ a * b.x, a * b.y }
> elseif (tonumber(b)) then
> return vec2{ a.x * b, a.y * b }
> else -- dot product
> return a.x * b.x + a.y * b.y;
> end
> end
> function vec2_meta.__unm(a) return vec2{ -a.x, -a.y } end
> function vec2_normalize(a)
> -- normalizes a. If a has 0 or near-zero length, sets a to an arbitrary unit vector (go ahead and sue me!)
>
> local d2 = a * a
> if d2 < 0.000001 then
> -- infinitesimal vector. Return arbitrary unit vector!
> a.x = 1
> a.y = 0
> else
> -- divide by the length to get a unit vector
> local length = math.sqrt(d2)
> a.x = a.x / length
> a.y = a.y / length
> end
> end
81c110
< if not vec2_tag then
---
> --[[ if not vec2_tag then
105c134
<
---
> ]]
107c136,137
< if type(t) == 'table' or tag(t) == vec2_tag then
---
> -- if type(t) == 'table' or tag(t) == vec2_tag then
> if (type(t) == 'table' or getmetatable(t) == vec2_meta) then
114c144,145
< settag(v, vec2_tag)
---
> -- settag(v, vec2_tag)
> setmetatable(v, vec2_meta)
119,136d149
<
< function vec2_normalize(a)
< -- normalizes a. If a has 0 or near-zero length, sets a to an arbitrary unit vector (go ahead and sue me!)
<
< local d2 = a * a
< if d2 < 0.000001 then
< -- infinitesimal vector. Return arbitrary unit vector!
< a.x = 1
< a.y = 0
< else
< -- divide by the length to get a unit vector
< local length = sqrt(d2)
< a.x = a.x / length
< a.y = a.y / length
< end
< end
<
<
155c168
< tinsert(self.new_actors, a)
---
> table.insert(self.new_actors, a)
180c193
< for i = 1, getn(gamestate.actors) do
---
> for i = 1, table.getn(gamestate.actors) do
183c196
< tinsert(gamestate.new_actors, gamestate.actors[i])
---
> table.insert(gamestate.new_actors, gamestate.actors[i])
190c203
< for i = 1, getn(gamestate.actors) do
---
> for i = 1, table.getn(gamestate.actors) do
203c216
< for i = 1, getn(gamestate.actors) do
---
> for i = 1, table.getn(gamestate.actors) do
268c281
< for i = 1, getn(argv) do
---
> for i = 1, table.getn(argv) do
277c290
< _ = [[
---
> --[[
295c308
< ]]; _ = nil;
---
> ]]
497c510
< dir = vec2{ random() * 2 - 1, random() * 2 - 1 }
---
> dir = vec2{ math.random() * 2 - 1, math.random() * 2 - 1 }
503c516
< p.countdown = (random() + random() + random()) / 3 * average_life
---
> p.countdown = (math.random() + math.random() + math.random()) / 3 * average_life
528c541
< for i = 1, getn(gs.actors) do
---
> for i = 1, table.getn(gs.actors) do
537c550
< local d = sqrt(d2)
---
> local d = math.sqrt(d2)
613c626
< local split_speed = sqrt(2 * collision_energy / a.mass) * 0.35
---
> local split_speed = math.sqrt(2 * collision_energy / a.mass) * 0.35
678c691
< return image_table[random(getn(image_table))]
---
> return image_table[math.random(table.getn(image_table))]
697c710
< local speed = sqrt(a.velocity * a.velocity)
---
> local speed = math.sqrt(a.velocity * a.velocity)
699c712
< local new_speed = SPEED_TURNOVER_THRESHOLD + sqrt(speed - SPEED_TURNOVER_THRESHOLD)
---
> local new_speed = SPEED_TURNOVER_THRESHOLD + math.sqrt(speed - SPEED_TURNOVER_THRESHOLD)
739c752
< local edge = random(w * 2 + h * 2)
---
> local edge = math.random(w * 2 + h * 2)
754c767
< vel = vel * (random(50) + 50)
---
> vel = vel * (math.random(50) + 50)
796c809
< particle_spray(self.position, accel * -0.10, floor(sqrt(accel * accel) * 0.0015), 150, 200)
---
> particle_spray(self.position, accel * -0.10, math.floor(math.sqrt(accel * accel) * 0.0015), 150, 200)
802c815
< for i = 1, getn(gs.actors) do
---
> for i = 1, table.getn(gs.actors) do
1025c1038
< local digit = mod(score, 10)
---
> local digit = math.mod(score, 10)
1029c1042
< score = floor(score / 10)
---
> score = math.floor(score / 10)
1096c1109
< for i = 1,getn(free_ship_schedule) do
---
> for i = 1,table.getn(free_ship_schedule) do
1103c1116,1117
< local delta = floor((manager.score - threshold) / interval) - floor((score0 - threshold) / interval)
---
> local delta = math.floor((manager.score -
> threshold) / interval) - math.floor((score0 - threshold) / interval)
1110,1111c1124,1125
< local ramp = exp(-manager.score / 10000) + 0.5
< manager.asteroid_spewer.period = (1 + sin(manager.score / 500) * 0.25) * ramp * BASE_SPEW_PERIOD
---
> local ramp = math.exp(-manager.score / 10000) + 0.5
> manager.asteroid_spewer.period = (1 + math.sin(manager.score / 500) * 0.25) * ramp * BASE_SPEW_PERIOD
1146,1148c1160,1163
< position = { random(gamestate.screen.w), random(gamestate.screen.h) },
< velocity = { (random()*2 - 1) * 100, (random()*2 - 1) * 100 }, -- pixels/sec
< size = random(3)
---
> position = { math.random(gamestate.screen.w),
> math.random(gamestate.screen.h) },
> velocity = { (math.random()*2 - 1) * 100, (math.random()*2 - 1) * 100 }, -- pixels/sec
> size = math.random(3)