diff --git a/src/modules/event/Event.cpp b/src/modules/event/Event.cpp index ffa25807f..684683558 100644 --- a/src/modules/event/Event.cpp +++ b/src/modules/event/Event.cpp @@ -24,18 +24,20 @@ namespace love { namespace event { - Message::Message(std::string name, int nargs, ...) - : name(name), nargs(nargs) + Message::Message(std::string name, Variant *a, Variant *b, Variant *c, Variant *d) + : name(name), nargs(0) { - args = new Variant*[nargs]; - va_list arg; - va_start(arg, nargs); - for (int i = 0; i < nargs; i++) + args[0] = a; + args[1] = b; + args[2] = c; + args[3] = d; + for (int i = 0; i < 4; i++) { - args[i] = va_arg(arg, Variant*); + if (!args[i]) + continue; args[i]->retain(); + nargs++; } - va_end(arg); } Message::~Message() @@ -55,13 +57,16 @@ namespace event Message *Message::fromLua(lua_State *L, int n) { std::string name = luaL_checkstring(L, n); - Message *m = new Message(name, 0); - int nargs = lua_gettop(L)-n; - delete[] m->args; - m->args = new Variant*[nargs]; - for (int i = 0; i < nargs; i++) + n++; + Message *m = new Message(name); + for (int i = 0; i < 4; i++) { + if (lua_isnoneornil(L, n+i)) + break; m->args[i] = Variant::fromLua(L, n+i); + if (!m->args[i]) + break; + m->nargs++; } return m; } diff --git a/src/modules/event/Event.h b/src/modules/event/Event.h index 77dc8a931..789f99b87 100644 --- a/src/modules/event/Event.h +++ b/src/modules/event/Event.h @@ -39,11 +39,11 @@ namespace event { private: std::string name; - Variant **args; + Variant *args[4]; int nargs; public: - Message(std::string name, int nargs, ...); + Message(std::string name, Variant *a = NULL, Variant *b = NULL, Variant *c = NULL, Variant *d = NULL); ~Message(); int toLua(lua_State *L); diff --git a/src/modules/event/sdl/Event.cpp b/src/modules/event/sdl/Event.cpp index 8c65db7b1..4c4472689 100644 --- a/src/modules/event/sdl/Event.cpp +++ b/src/modules/event/sdl/Event.cpp @@ -98,7 +98,7 @@ namespace sdl { arg1 = new Variant(txt, strlen(txt)); arg2 = new Variant((double) e.key.keysym.unicode); - msg = new Message("keypressed", 2, arg1, arg2); + msg = new Message("keypressed", arg1, arg2); arg1->release(); arg2->release(); } @@ -107,7 +107,7 @@ namespace sdl if (keys.find(e.key.keysym.sym, key) && love::event::Event::keys.find(key, txt)) { arg1 = new Variant(txt, strlen(txt)); - msg = new Message("keyreleased", 1, arg1); + msg = new Message("keyreleased", arg1); arg1->release(); } break; @@ -119,7 +119,7 @@ namespace sdl arg2 = new Variant((double) e.button.y); arg3 = new Variant(txt, strlen(txt)); msg = new Message((e.type == SDL_MOUSEBUTTONDOWN) ? - "mousepressed" : "mousereleased", 3, + "mousepressed" : "mousereleased", arg1, arg2, arg3); arg1->release(); arg2->release(); @@ -131,7 +131,7 @@ namespace sdl arg1 = new Variant((double) (e.jbutton.which+1)); arg2 = new Variant((double) (e.jbutton.button+1)); msg = new Message((e.type == SDL_JOYBUTTONDOWN) ? - "joystickpressed" : "joystickreleased", 2, + "joystickpressed" : "joystickreleased", arg1, arg2); arg1->release(); arg2->release(); @@ -139,11 +139,11 @@ namespace sdl case SDL_ACTIVEEVENT: arg1 = new Variant(e.active.gain != 0); if (e.active.state & SDL_APPINPUTFOCUS) - msg = new Message("focus", 1, arg1); + msg = new Message("focus", arg1); arg1->release(); break; case SDL_QUIT: - msg = new Message("quit", 0); + msg = new Message("quit"); break; } diff --git a/src/modules/event/sdl/wrap_Event.cpp b/src/modules/event/sdl/wrap_Event.cpp index 028f24eaa..fef631723 100644 --- a/src/modules/event/sdl/wrap_Event.cpp +++ b/src/modules/event/sdl/wrap_Event.cpp @@ -99,7 +99,7 @@ namespace sdl int w_quit(lua_State * L) { - Message *m = new Message("quit", 0); + Message *m = new Message("quit"); instance->push(m); return 1; } diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index fc667047f..7ba51de0d 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -380,7 +380,7 @@ function love.run() -- Process events. if love.event then love.event.pump() - for e,a,b,c in love.event.poll() do + for e,a,b,c,d in love.event.poll() do if e == "quit" then if not love.quit or not love.quit() then if love.audio then @@ -389,7 +389,7 @@ function love.run() return end end - love.handlers[e](a,b,c) + love.handlers[e](a,b,c,d) end end diff --git a/src/scripts/boot.lua.h b/src/scripts/boot.lua.h index e46069be6..2a622be90 100644 --- a/src/scripts/boot.lua.h +++ b/src/scripts/boot.lua.h @@ -652,9 +652,9 @@ const unsigned char boot_lua[] = 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x75, 0x6d, 0x70, 0x28, 0x29, 0x0a, - 0x09, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x65, 0x2c, 0x61, 0x2c, 0x62, 0x2c, 0x63, 0x20, 0x69, 0x6e, 0x20, - 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x6f, 0x6c, 0x6c, 0x28, 0x29, 0x20, - 0x64, 0x6f, 0x0a, + 0x09, 0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x65, 0x2c, 0x61, 0x2c, 0x62, 0x2c, 0x63, 0x2c, 0x64, 0x20, 0x69, + 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x6f, 0x6c, 0x6c, 0x28, + 0x29, 0x20, 0x64, 0x6f, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x71, 0x75, 0x69, 0x74, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x71, @@ -669,7 +669,7 @@ const unsigned char boot_lua[] = 0x09, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x5b, - 0x65, 0x5d, 0x28, 0x61, 0x2c, 0x62, 0x2c, 0x63, 0x29, 0x0a, + 0x65, 0x5d, 0x28, 0x61, 0x2c, 0x62, 0x2c, 0x63, 0x2c, 0x64, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,0x0a, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x20, 0x64, 0x74, 0x2c, 0x20, 0x61, 0x73,