aboutsummaryrefslogtreecommitdiff
path: root/src/lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/audio/luaopen_audio.cpp9
-rw-r--r--src/lua/core/luaopen_core.cpp3
-rw-r--r--src/lua/embed/boot.lua.h4
-rw-r--r--src/lua/event/luaopen_event.cpp22
-rw-r--r--src/lua/graphics/luaopen_graphics.cpp8
5 files changed, 27 insertions, 19 deletions
diff --git a/src/lua/audio/luaopen_audio.cpp b/src/lua/audio/luaopen_audio.cpp
index 992c3ec..73c5bea 100644
--- a/src/lua/audio/luaopen_audio.cpp
+++ b/src/lua/audio/luaopen_audio.cpp
@@ -1,5 +1,3 @@
-#include <SDL2/SDL.h>
-
#include "lua/luax.h"
#include "libjin/jin.h"
@@ -7,14 +5,19 @@ namespace jin
{
namespace lua
{
+ using namespace jin::audio;
+
static int l_init(lua_State* L)
{
- if (SDL_Init(SDL_INIT_AUDIO) < 0)
+ SDLAudioSetting setting;
+ if (! SDLAudio::get()->init(&setting))
{
luax_error(L, "could not init audio");
luax_pushboolean(L, false);
return 1;
}
+ luax_pushboolean(L, true);
+ return 1;
}
static int l_newSound(lua_State* L)
diff --git a/src/lua/core/luaopen_core.cpp b/src/lua/core/luaopen_core.cpp
index c8df1b6..0e79ff5 100644
--- a/src/lua/core/luaopen_core.cpp
+++ b/src/lua/core/luaopen_core.cpp
@@ -9,7 +9,8 @@ namespace lua
static int l_running(lua_State* L)
{
- bool running = Game::get()->running();
+ static Game* game = Game::get();
+ bool running = game->running();
luax_pushboolean(L, running);
return 1;
}
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h
index 21c1899..2a9cfc5 100644
--- a/src/lua/embed/boot.lua.h
+++ b/src/lua/embed/boot.lua.h
@@ -86,7 +86,9 @@ function jin.core.run()
-- update
if onUpdate then
- onUpdate(dt)
+ -- while do
+ onUpdate(dt)
+ -- end
end
-- bind to default render buffer
diff --git a/src/lua/event/luaopen_event.cpp b/src/lua/event/luaopen_event.cpp
index 8a84c97..2d1e52f 100644
--- a/src/lua/event/luaopen_event.cpp
+++ b/src/lua/event/luaopen_event.cpp
@@ -1,8 +1,6 @@
/**
* Event module
*/
-#include <SDl2/SDL.h>
-
#include "lua/luax.h"
#include "libjin/jin.h"
@@ -36,50 +34,50 @@ namespace lua
{
// table to store events
luax_newtable(L);
- SDL_Event e;
+ static Event e;
int i = 1;
poll:
- while (SDL_PollEvent(&e))
+ while (pollEvent(&e))
{
// each event is a table
luax_newtable(L);
switch (e.type)
{
- case SDL_QUIT:
+ case EventType::QUIT:
luax_setfield_string(L, "type", "quit");
break;
- case SDL_KEYDOWN:
+ case EventType::KEYDOWN:
luax_setfield_string(L, "type", "keydown");
luax_setfield_string(L, "key", SDL_GetKeyName(e.key.keysym.sym));
break;
- case SDL_KEYUP:
+ case EventType::KEYUP:
luax_setfield_string(L, "type", "keyup");
luax_setfield_string(L, "key", SDL_GetKeyName(e.key.keysym.sym));
break;
- case SDL_MOUSEMOTION:
+ case EventType::MOUSEMOTION:
luax_setfield_string(L, "type", "mousemotion");
luax_setfield_number(L, "x", e.motion.x);
luax_setfield_number(L, "y", e.motion.y);
break;
- case SDL_MOUSEBUTTONDOWN:
+ case EventType::MOUSEBUTTONDOWN:
luax_setfield_string(L, "type", "mousebuttondown");
luax_setfield_string(L, "button", buttonstr(e.button.button));
luax_setfield_number(L, "x", e.button.x);
luax_setfield_number(L, "y", e.button.y);
break;
- case SDL_MOUSEBUTTONUP:
+ case EventType::MOUSEBUTTONUP:
luax_setfield_string(L, "type", "mousebuttonup");
luax_setfield_string(L, "button", buttonstr(e.button.button));
luax_setfield_number(L, "x", e.button.x);
luax_setfield_number(L, "y", e.button.y);
break;
- case SDL_MOUSEWHEEL:
+ case EventType::MOUSEWHEEL:
luax_setfield_string(L, "type", "wheel");
if(e.wheel.x == -1)
luax_setfield_string(L, "x", "left");
@@ -106,7 +104,7 @@ namespace lua
}
return 1;
}
-
+
static const luaL_Reg f[] = {
{"poll", l_event_poll},
{0 ,0 }
diff --git a/src/lua/graphics/luaopen_graphics.cpp b/src/lua/graphics/luaopen_graphics.cpp
index be40247..f0bae67 100644
--- a/src/lua/graphics/luaopen_graphics.cpp
+++ b/src/lua/graphics/luaopen_graphics.cpp
@@ -33,8 +33,12 @@ namespace lua
setting.height = luax_getfield_integer(L, 1, "height");
setting.title = luax_getfield_string(L, 1, "title");
setting.vsync = luax_getfield_bool(L, 1, "vsync");
- wnd->init(&setting);
- luax_pushboolean(L, 1);
+ if (!wnd->init(&setting))
+ {
+ luax_pushboolean(L, false);
+ return 1;
+ }
+ luax_pushboolean(L, true);
return 1;
}