diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/audio/Source.h | 93 | ||||
-rw-r--r-- | src/lua/libraries/luax/luax.h (renamed from src/3rdparty/luax/luax.h) | 0 | ||||
-rw-r--r-- | src/lua/modules/audio/luaopen_Source.cpp (renamed from src/lua/audio/luaopen_Source.cpp) | 4 | ||||
-rw-r--r-- | src/lua/modules/audio/luaopen_audio.cpp (renamed from src/lua/audio/luaopen_audio.cpp) | 4 | ||||
-rw-r--r-- | src/lua/modules/bit/luaopen_bit.cpp (renamed from src/lua/bit/luaopen_bit.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/core/luaopen_core.cpp (renamed from src/lua/core/luaopen_core.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/embed/boot.lua.h (renamed from src/lua/embed/boot.lua.h) | 23 | ||||
-rw-r--r-- | src/lua/modules/embed/embed.h (renamed from src/lua/embed/embed.h) | 0 | ||||
-rw-r--r-- | src/lua/modules/embed/graphics.lua.h (renamed from src/lua/embed/graphics.lua.h) | 0 | ||||
-rw-r--r-- | src/lua/modules/embed/keyboard.lua.h (renamed from src/lua/embed/keyboard.lua.h) | 0 | ||||
-rw-r--r-- | src/lua/modules/embed/mouse.lua.h (renamed from src/lua/embed/mouse.lua.h) | 0 | ||||
-rw-r--r-- | src/lua/modules/embed/net.lua.h (renamed from src/lua/embed/net.lua.h) | 0 | ||||
-rw-r--r-- | src/lua/modules/embed/path.lua.h (renamed from src/lua/embed/path.lua.h) | 0 | ||||
-rw-r--r-- | src/lua/modules/event/luaopen_event.cpp (renamed from src/lua/event/luaopen_event.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/filesystem/luaopen_filesystem.cpp (renamed from src/lua/filesystem/luaopen_filesystem.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/graphics/luaopen_Canvas.cpp (renamed from src/lua/graphics/luaopen_Canvas.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/graphics/luaopen_Font.cpp (renamed from src/lua/graphics/luaopen_Font.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/graphics/luaopen_Image.cpp (renamed from src/lua/graphics/luaopen_Image.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/graphics/luaopen_JSL.cpp (renamed from src/lua/graphics/luaopen_JSL.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/graphics/luaopen_graphics.cpp (renamed from src/lua/graphics/luaopen_graphics.cpp) | 6 | ||||
-rw-r--r-- | src/lua/modules/joypad/luaopen_joypad.cpp (renamed from src/lua/joypad/luaopen_joypad.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/keyboard/luaopen_keyboard.cpp (renamed from src/lua/keyboard/luaopen_keyboard.cpp) | 4 | ||||
-rw-r--r-- | src/lua/modules/luaopen_jin.cpp (renamed from src/lua/luaopen_jin.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/luaopen_jin.h (renamed from src/lua/luaopen_jin.h) | 2 | ||||
-rw-r--r-- | src/lua/modules/luax.h (renamed from src/lua/luax.h) | 2 | ||||
-rw-r--r-- | src/lua/modules/math/luaopen_math.cpp (renamed from src/lua/math/luaopen_math.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/mouse/luaopen_mouse.cpp (renamed from src/lua/mouse/luaopen_mouse.cpp) | 2 | ||||
-rw-r--r-- | src/lua/modules/net/Buffer.h (renamed from src/lua/net/Buffer.h) | 2 | ||||
-rw-r--r-- | src/lua/modules/net/luaopen_Buffer.cpp (renamed from src/lua/net/luaopen_Buffer.cpp) | 4 | ||||
-rw-r--r-- | src/lua/modules/net/luaopen_Socket.cpp (renamed from src/lua/net/luaopen_Socket.cpp) | 4 | ||||
-rw-r--r-- | src/lua/modules/net/luaopen_net.cpp (renamed from src/lua/net/luaopen_net.cpp) | 4 | ||||
-rw-r--r-- | src/lua/modules/thread/Thread.cpp (renamed from src/lua/thread/Thread.cpp) | 0 | ||||
-rw-r--r-- | src/lua/modules/thread/Thread.h (renamed from src/lua/thread/Thread.h) | 2 | ||||
-rw-r--r-- | src/lua/modules/thread/luaopen_thread.cpp (renamed from src/lua/thread/luaopen_thread.cpp) | 6 | ||||
-rw-r--r-- | src/lua/modules/time/luaopen_time.cpp (renamed from src/lua/time/luaopen_time.cpp) | 2 | ||||
-rw-r--r-- | src/lua/resources/embed.py (renamed from src/data/embed.py) | 0 | ||||
-rw-r--r-- | src/lua/resources/font.ttf (renamed from src/data/font.ttf) | bin | 84564 -> 84564 bytes | |||
-rw-r--r-- | src/lua/resources/font.ttf.h (renamed from src/data/font.ttf.h) | 0 | ||||
-rw-r--r-- | src/lua/thread/luaopen_Thread.cpp | 248 | ||||
-rw-r--r-- | src/main.cpp | 4 |
40 files changed, 52 insertions, 386 deletions
diff --git a/src/lua/audio/Source.h b/src/lua/audio/Source.h deleted file mode 100644 index 094ad12..0000000 --- a/src/lua/audio/Source.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef __JIN_LUA_AUDIO_SOURCE_H -#define __JIN_LUA_AUDIO_SOURCE_H -#include "libjin/jin.h" -#include "../luaopen_types.h" - -namespace jin -{ -namespace lua -{ -namespace audio -{ - - class Source : public Object - { - public: - void play() - { - source->play(); - } - - void stop() - { - source->stop(); - } - - void pause() - { - source->pause(); - } - - void resume() - { - source->resume(); - } - - void rewind() - { - source->rewind(); - } - - bool isStopped() const - { - return source->isStopped(); - } - - bool isPaused() const - { - return source->isPaused(); - } - - void setPitch(float pitch) - { - source->setPitch(pitch); - } - - void setVolume(float volume) - { - source->setVolume(volume); - } - - bool setLoop(bool loop) - { - return source->setLoop(loop); - } - - void setRate(float rate) - { - source->setRate(rate); - } - - inline static Source * createSource(void* mem, size_t size) - { - Source* src = new Source; - src->source = jin::audio::SDLSource::createSource(mem, size); - return src; - } - - private: - ~Source() - { - source->stop(); - delete source; - } - - jin::audio::SDLSource* source; - - }; - -} // audio -} // lua -} // jin - -#endif
\ No newline at end of file diff --git a/src/3rdparty/luax/luax.h b/src/lua/libraries/luax/luax.h index 56023b3..56023b3 100644 --- a/src/3rdparty/luax/luax.h +++ b/src/lua/libraries/luax/luax.h diff --git a/src/lua/audio/luaopen_Source.cpp b/src/lua/modules/audio/luaopen_Source.cpp index aa71184..4c98ead 100644 --- a/src/lua/audio/luaopen_Source.cpp +++ b/src/lua/modules/audio/luaopen_Source.cpp @@ -1,6 +1,6 @@ -#include "lua/luax.h" #include "libjin/jin.h" -#include "../common/common.h" +#include "lua/modules/luax.h" +#include "lua/common/common.h" namespace jin { diff --git a/src/lua/audio/luaopen_audio.cpp b/src/lua/modules/audio/luaopen_audio.cpp index c87df3a..1c44374 100644 --- a/src/lua/audio/luaopen_audio.cpp +++ b/src/lua/modules/audio/luaopen_audio.cpp @@ -1,5 +1,5 @@ -#include "lua/luax.h" -#include "../common/common.h" +#include "lua/modules/luax.h" +#include "lua/common/common.h" #include "libjin/jin.h" namespace jin diff --git a/src/lua/bit/luaopen_bit.cpp b/src/lua/modules/bit/luaopen_bit.cpp index 3b086bb..5b18125 100644 --- a/src/lua/bit/luaopen_bit.cpp +++ b/src/lua/modules/bit/luaopen_bit.cpp @@ -1,4 +1,4 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "libjin/jin.h" #include <cstdlib> diff --git a/src/lua/core/luaopen_core.cpp b/src/lua/modules/core/luaopen_core.cpp index 3b234b6..0243554 100644 --- a/src/lua/core/luaopen_core.cpp +++ b/src/lua/modules/core/luaopen_core.cpp @@ -1,4 +1,4 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "libjin/jin.h" namespace jin diff --git a/src/lua/embed/boot.lua.h b/src/lua/modules/embed/boot.lua.h index 36615b0..32d3e1d 100644 --- a/src/lua/embed/boot.lua.h +++ b/src/lua/modules/embed/boot.lua.h @@ -26,6 +26,16 @@ local function call(func, ...) end end +jin.core.setHandler = function(handler) + if handler == nil then + return + end + jin.core.onLoad = handler.onLoad + jin.core.onEvent = handler.onEvent + jin.core.onUpdate = handler.onUpdate + jin.core.onDraw = handler.onDraw +end + function jin.core.run() call(jin.core.onLoad) local previous = jin.time.second() @@ -96,18 +106,18 @@ jin.nogame = { ww2 = 6*2, speed = 4, t = 0, - load = function() + onLoad = function() local nogame = jin.nogame nogame.cw = nogame.sw / nogame.cs nogame.ch = nogame.sh / nogame.cs nogame.t = nogame.ww - 1 end, - event = function(e) + onEvent = function(e) if e.type == 'quit' then jin.core.stop() end end, - update = function(dt) + onUpdate = function(dt) local nogame = jin.nogame nogame.t = nogame.t + dt * nogame.speed if nogame.t > nogame.ww2 then @@ -124,7 +134,7 @@ jin.nogame = { jin.graphics.color(155 + 100 * math.sin(fact), 155 + 100 * math.cos(fact), 155 + 100 * math.sin(fact * fact), 255) jin.graphics.circle("fill", x*nogame.cs + nogame.cs/2, y*nogame.cs + nogame.cs/2, r) end, - draw = function() + onDraw = function() local nogame = jin.nogame for y = 0, nogame.ch - 1 do for x = 0, nogame.cw - 1 do @@ -145,10 +155,7 @@ local function boot() jin.core.run() else -- no game - jin.core.onLoad = jin.nogame.load - jin.core.onEvent = jin.nogame.event - jin.core.onUpdate = jin.nogame.update - jin.core.onDraw = jin.nogame.draw + jin.core.setHandler(jin.nogame) jin.core.run() end -- quit subsystems diff --git a/src/lua/embed/embed.h b/src/lua/modules/embed/embed.h index 18ed1d8..18ed1d8 100644 --- a/src/lua/embed/embed.h +++ b/src/lua/modules/embed/embed.h diff --git a/src/lua/embed/graphics.lua.h b/src/lua/modules/embed/graphics.lua.h index 1414efc..1414efc 100644 --- a/src/lua/embed/graphics.lua.h +++ b/src/lua/modules/embed/graphics.lua.h diff --git a/src/lua/embed/keyboard.lua.h b/src/lua/modules/embed/keyboard.lua.h index 77bf3a9..77bf3a9 100644 --- a/src/lua/embed/keyboard.lua.h +++ b/src/lua/modules/embed/keyboard.lua.h diff --git a/src/lua/embed/mouse.lua.h b/src/lua/modules/embed/mouse.lua.h index 3c222f3..3c222f3 100644 --- a/src/lua/embed/mouse.lua.h +++ b/src/lua/modules/embed/mouse.lua.h diff --git a/src/lua/embed/net.lua.h b/src/lua/modules/embed/net.lua.h index 4d89dc7..4d89dc7 100644 --- a/src/lua/embed/net.lua.h +++ b/src/lua/modules/embed/net.lua.h diff --git a/src/lua/embed/path.lua.h b/src/lua/modules/embed/path.lua.h index 648adf8..648adf8 100644 --- a/src/lua/embed/path.lua.h +++ b/src/lua/modules/embed/path.lua.h diff --git a/src/lua/event/luaopen_event.cpp b/src/lua/modules/event/luaopen_event.cpp index fd113c6..af9f8fc 100644 --- a/src/lua/event/luaopen_event.cpp +++ b/src/lua/modules/event/luaopen_event.cpp @@ -1,7 +1,7 @@ /** * Event module */ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "libjin/jin.h" namespace jin diff --git a/src/lua/filesystem/luaopen_filesystem.cpp b/src/lua/modules/filesystem/luaopen_filesystem.cpp index f764a68..55f4c06 100644 --- a/src/lua/filesystem/luaopen_filesystem.cpp +++ b/src/lua/modules/filesystem/luaopen_filesystem.cpp @@ -1,4 +1,4 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "libjin/jin.h" #include <string> diff --git a/src/lua/graphics/luaopen_Canvas.cpp b/src/lua/modules/graphics/luaopen_Canvas.cpp index 0009ff4..d94e578 100644 --- a/src/lua/graphics/luaopen_Canvas.cpp +++ b/src/lua/modules/graphics/luaopen_Canvas.cpp @@ -1,4 +1,4 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "lua/common/common.h" #include "libjin/jin.h" diff --git a/src/lua/graphics/luaopen_Font.cpp b/src/lua/modules/graphics/luaopen_Font.cpp index 5e13806..c5789ad 100644 --- a/src/lua/graphics/luaopen_Font.cpp +++ b/src/lua/modules/graphics/luaopen_Font.cpp @@ -1,4 +1,4 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "lua/common/common.h" #include "libjin/jin.h" diff --git a/src/lua/graphics/luaopen_Image.cpp b/src/lua/modules/graphics/luaopen_Image.cpp index df9b411..0f68873 100644 --- a/src/lua/graphics/luaopen_Image.cpp +++ b/src/lua/modules/graphics/luaopen_Image.cpp @@ -1,4 +1,4 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "lua/common/common.h" #include "libjin/jin.h" diff --git a/src/lua/graphics/luaopen_JSL.cpp b/src/lua/modules/graphics/luaopen_JSL.cpp index 1c46f84..c7a257a 100644 --- a/src/lua/graphics/luaopen_JSL.cpp +++ b/src/lua/modules/graphics/luaopen_JSL.cpp @@ -1,4 +1,4 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "lua/common/common.h" #include "libjin/jin.h" diff --git a/src/lua/graphics/luaopen_graphics.cpp b/src/lua/modules/graphics/luaopen_graphics.cpp index c189675..f0a7f5b 100644 --- a/src/lua/graphics/luaopen_graphics.cpp +++ b/src/lua/modules/graphics/luaopen_graphics.cpp @@ -1,7 +1,7 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "libjin/jin.h" #include "lua/common/common.h" -#include "lua/embed/graphics.lua.h" +#include "lua/modules/embed/graphics.lua.h" namespace jin { @@ -395,7 +395,7 @@ namespace lua { if (context.defaultFont == 0) { - #include "data/font.ttf.h" + #include "lua/resources/font.ttf.h" // load default font context.defaultFont = new Font(); context.defaultFont->loadb(font_ttf); diff --git a/src/lua/joypad/luaopen_joypad.cpp b/src/lua/modules/joypad/luaopen_joypad.cpp index 6c98c3b..d305878 100644 --- a/src/lua/joypad/luaopen_joypad.cpp +++ b/src/lua/modules/joypad/luaopen_joypad.cpp @@ -1,5 +1,5 @@ #include "libjin/jin.h" -#include "lua/luax.h" +#include "lua/modules/luax.h" namespace jin { diff --git a/src/lua/keyboard/luaopen_keyboard.cpp b/src/lua/modules/keyboard/luaopen_keyboard.cpp index ea1386c..9d27a4f 100644 --- a/src/lua/keyboard/luaopen_keyboard.cpp +++ b/src/lua/modules/keyboard/luaopen_keyboard.cpp @@ -1,5 +1,5 @@ -#include "lua/luax.h" -#include "lua/embed/keyboard.lua.h" +#include "lua/modules/luax.h" +#include "lua/modules/embed/keyboard.lua.h" namespace jin { diff --git a/src/lua/luaopen_jin.cpp b/src/lua/modules/luaopen_jin.cpp index ffb0f45..dbbac31 100644 --- a/src/lua/luaopen_jin.cpp +++ b/src/lua/modules/luaopen_jin.cpp @@ -1,5 +1,5 @@ #include "luaopen_jin.h" -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "embed/embed.h" namespace jin diff --git a/src/lua/luaopen_jin.h b/src/lua/modules/luaopen_jin.h index 8bd902e..07531b2 100644 --- a/src/lua/luaopen_jin.h +++ b/src/lua/modules/luaopen_jin.h @@ -21,7 +21,7 @@ #ifndef __JIN_M_JIN_H #define __JIN_M_JIN_H -#include "lua/luax.h" +#include "luax.h" #define MODULE_NAME "jin" #define VERSION "0.1.1" diff --git a/src/lua/luax.h b/src/lua/modules/luax.h index 78c15a6..89e456e 100644 --- a/src/lua/luax.h +++ b/src/lua/modules/luax.h @@ -2,6 +2,6 @@ #define __JIN_LUA_LUAX_H #include "LuaJIT/lua.hpp" -#include "3rdparty/luax/luax.h" +#include "lua/libraries/luax/luax.h" #endif
\ No newline at end of file diff --git a/src/lua/math/luaopen_math.cpp b/src/lua/modules/math/luaopen_math.cpp index 0a82271..fa59e04 100644 --- a/src/lua/math/luaopen_math.cpp +++ b/src/lua/modules/math/luaopen_math.cpp @@ -1,4 +1,4 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "libjin/jin.h" namespace jin diff --git a/src/lua/mouse/luaopen_mouse.cpp b/src/lua/modules/mouse/luaopen_mouse.cpp index d3488f3..f907abb 100644 --- a/src/lua/mouse/luaopen_mouse.cpp +++ b/src/lua/modules/mouse/luaopen_mouse.cpp @@ -1,4 +1,4 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "libjin/jin.h" namespace jin diff --git a/src/lua/net/Buffer.h b/src/lua/modules/net/Buffer.h index 89a4fc0..31e6df8 100644 --- a/src/lua/net/Buffer.h +++ b/src/lua/modules/net/Buffer.h @@ -3,7 +3,7 @@ #include <cstring> #include <cstdlib> -#include "../common/common.h" +#include "lua/common/common.h" namespace jin { diff --git a/src/lua/net/luaopen_Buffer.cpp b/src/lua/modules/net/luaopen_Buffer.cpp index 1018dcc..cb5b952 100644 --- a/src/lua/net/luaopen_Buffer.cpp +++ b/src/lua/modules/net/luaopen_Buffer.cpp @@ -1,5 +1,5 @@ -#include "lua/luax.h" -#include "../common/common.h" +#include "lua/modules/luax.h" +#include "lua/common/common.h" #include "libjin/jin.h" #include "Buffer.h" diff --git a/src/lua/net/luaopen_Socket.cpp b/src/lua/modules/net/luaopen_Socket.cpp index def3d43..2e5d9f3 100644 --- a/src/lua/net/luaopen_Socket.cpp +++ b/src/lua/modules/net/luaopen_Socket.cpp @@ -1,5 +1,5 @@ -#include "lua/luax.h" -#include "../common/common.h" +#include "lua/modules/luax.h" +#include "lua/common/common.h" #include "libjin/jin.h" #include "Buffer.h" diff --git a/src/lua/net/luaopen_net.cpp b/src/lua/modules/net/luaopen_net.cpp index 12e87eb..e7e55c4 100644 --- a/src/lua/net/luaopen_net.cpp +++ b/src/lua/modules/net/luaopen_net.cpp @@ -1,6 +1,6 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "libjin/jin.h" -#include "../common/common.h" +#include "lua/common/common.h" #include "Buffer.h" namespace jin diff --git a/src/lua/thread/Thread.cpp b/src/lua/modules/thread/Thread.cpp index 8df3255..8df3255 100644 --- a/src/lua/thread/Thread.cpp +++ b/src/lua/modules/thread/Thread.cpp diff --git a/src/lua/thread/Thread.h b/src/lua/modules/thread/Thread.h index 3b2cbaf..645d4a1 100644 --- a/src/lua/thread/Thread.h +++ b/src/lua/modules/thread/Thread.h @@ -1,5 +1,5 @@ #include "libjin/jin.h" -#include "../common/common.h" +#include "lua/common/common.h" namespace jin { diff --git a/src/lua/thread/luaopen_thread.cpp b/src/lua/modules/thread/luaopen_thread.cpp index 141b873..65a7c29 100644 --- a/src/lua/thread/luaopen_thread.cpp +++ b/src/lua/modules/thread/luaopen_thread.cpp @@ -1,7 +1,7 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include "libjin/jin.h" -#include "../luaopen_jin.h" -#include "../common/common.h" +#include "lua/modules/luaopen_jin.h" +#include "lua/common/common.h" #include "Thread.h" namespace jin diff --git a/src/lua/time/luaopen_time.cpp b/src/lua/modules/time/luaopen_time.cpp index d77b713..39743b4 100644 --- a/src/lua/time/luaopen_time.cpp +++ b/src/lua/modules/time/luaopen_time.cpp @@ -1,4 +1,4 @@ -#include "lua/luax.h" +#include "lua/modules/luax.h" #include <SDL2/SDL.h> #include "libjin/jin.h" diff --git a/src/data/embed.py b/src/lua/resources/embed.py index 7eb825d..7eb825d 100644 --- a/src/data/embed.py +++ b/src/lua/resources/embed.py diff --git a/src/data/font.ttf b/src/lua/resources/font.ttf Binary files differindex 153c608..153c608 100644 --- a/src/data/font.ttf +++ b/src/lua/resources/font.ttf diff --git a/src/data/font.ttf.h b/src/lua/resources/font.ttf.h index 519d723..519d723 100644 --- a/src/data/font.ttf.h +++ b/src/lua/resources/font.ttf.h diff --git a/src/lua/thread/luaopen_Thread.cpp b/src/lua/thread/luaopen_Thread.cpp deleted file mode 100644 index 141b873..0000000 --- a/src/lua/thread/luaopen_Thread.cpp +++ /dev/null @@ -1,248 +0,0 @@ -#include "lua/luax.h" -#include "libjin/jin.h" -#include "../luaopen_jin.h" -#include "../common/common.h" -#include "Thread.h" - -namespace jin -{ -namespace lua -{ - - using thread::Thread; - - int luaopen_thread(lua_State* L); - - static inline Ref<Thread>& checkThread(lua_State* L) - { - Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_THREAD_THREAD); - return proxy->getRef<Thread>(); - } - - static int threadRunner(void* t) - { - Ref<Thread>& ref = *(Ref<Thread>*)t; - lua_State* L = lua_open(); - luax_openlibs(L); - luaopen_jin(L); - luax_getglobal(L, MODULE_NAME); - Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_THREAD_THREAD, sizeof(Proxy)); - ref.retain(); - proxy->bind(&ref); - luax_setfield(L, -2, "_curThread"); - luax_dostring(L, ref->code.c_str()); - luax_close(L); - return 0; - } - - static int l_thread_gc(lua_State* L) - { - Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_THREAD_THREAD); - proxy->release(); - return 0; - } - - static int l_start(lua_State* L) - { - Ref<Thread>& ref = checkThread(L); - bool result = ref->start(&ref); - luax_pushboolean(L, result); - return 1; - } - - static int l_wait(lua_State* L) - { - Ref<Thread>& ref = checkThread(L); - ref->wait(); - return 0; - } - - static int l_send(lua_State* L) - { - Ref<Thread>& ref = checkThread(L); - int slot = luax_checkinteger(L, 2); - const int vp = 3; - if (luax_isnumberstrict(L, vp)) - { - float real = luax_checknumber(L, vp); - ref->send(slot, real); - } - else if (luax_isbooleanstrict(L, vp)) - { - bool bol = luax_checkbool(L, vp); - ref->send(slot, bol); - } - else if (luax_isstringstrict(L, vp)) - { - const char* str = luax_checkstring(L, vp); - ref->send(slot, str); - } - else if (luax_isuserdata(L, vp)) - { - void* p = luax_touserdata(L, vp); - ref->send(slot, p); - } - else if (luax_islightuserdata(L, vp)) - { - void* p = luax_tolightuserdata(L, vp); - ref->send(slot, p); - } - return 0; - } - - static int l_receive(lua_State* L) - { - Ref<Thread>& ref = checkThread(L); - int slot = luax_checkinteger(L, 2); - bool result = ref->receive(slot); - luax_pushboolean(L, result); - return 1; - } - - static int l_fetch(lua_State* L) - { - Ref<Thread>& ref = checkThread(L); - int slot = luax_checkinteger(L, 2); - Thread::Variant v = ref->fetch(slot); - switch (v.type) - { - case thread::Thread::Variant::INTERGER: - luax_pushinteger(L, v.integer); - break; - - case thread::Thread::Variant::BOOLEAN: - luax_pushboolean(L, v.boolean); - break; - - case thread::Thread::Variant::CSTRING: - luax_pushstring(L, v.cstring); - break; - - case thread::Thread::Variant::REAL: - luax_pushnumber(L, v.real); - break; - - case thread::Thread::Variant::POINTER: - Proxy* p = (Proxy*)v.pointer; - Proxy* proxy = (Proxy*)luax_newinstance(L, p->getObjectType(), sizeof(Proxy)); - p->reference->retain(); - proxy->bind(p->reference); - break; - - } - return 1; - } - - static int l_demand(lua_State* L) - { - Ref<Thread>& ref = checkThread(L); - int slot = luax_checkinteger(L, 2); - Thread::Variant v = ref->demand(slot); - switch (v.type) - { - case thread::Thread::Variant::INTERGER: - luax_pushinteger(L, v.integer); - break; - - case thread::Thread::Variant::BOOLEAN: - luax_pushboolean(L, v.boolean); - break; - - case thread::Thread::Variant::CSTRING: - luax_pushstring(L, v.cstring); - break; - - case thread::Thread::Variant::REAL: - luax_pushnumber(L, v.real); - break; - - case thread::Thread::Variant::POINTER: - Proxy* p = (Proxy*)v.pointer; - Proxy* proxy = (Proxy*)luax_newinstance(L, p->getObjectType(), sizeof(Proxy)); - p->reference->retain(); - proxy->bind(p->reference); - break; - - } - return 1; - } - - static int l_remove(lua_State* L) - { - Ref<Thread>& ref = checkThread(L); - int slot = luax_checkinteger(L, 2); - ref->remove(slot); - return 0; - } - - static int l_getName(lua_State* L) - { - Ref<Thread>& ref = checkThread(L); - const char* name = ref->getName(); - luax_pushstring(L, name); - return 1; - } - - static int l_isRunning(lua_State* L) - { - Ref<Thread>& ref = checkThread(L); - bool running = ref->isRunning(); - luax_pushboolean(L, running); - return 1; - } - - static const luaL_Reg thread_function[] = { - { "__gc", l_thread_gc }, - { "start", l_start }, - { "wait", l_wait }, - { "send", l_send }, - { "receive", l_receive }, - { "fetch", l_fetch }, - { "demand", l_demand }, - { "remove", l_remove }, - { "getName", l_getName }, - { "isRunning", l_isRunning }, - { 0, 0 } - }; - - static int luaopen_Thread(lua_State* L) - { - luax_newtype(L, JIN_THREAD_THREAD, thread_function); - - return 0; - } - - static int l_newThread(lua_State* L) - { - const char* name = luax_checkstring(L, 1); - const char* code = luax_checkstring(L, 2); - Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_THREAD_THREAD, sizeof(Proxy)); - Thread* thread = new Thread(name, code, threadRunner); - proxy->bind(new Ref<Thread>(thread, JIN_THREAD_THREAD)); - return 1; - } - - static int l_getThread(lua_State* L) - { - luax_getglobal(L, MODULE_NAME); - luax_getfield(L, -1, "_curThread"); - return 1; - } - - static const luaL_Reg f[] = { - { "newThread", l_newThread }, - { "getThread", l_getThread }, - { 0, 0 } - }; - - int luaopen_thread(lua_State* L) - { - luaopen_Thread(L); - - luax_newlib(L, f); - - return 1; - } - -} // lua -} // jin
\ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0d7b5d3..4137b1e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,8 +3,8 @@ # include <direct.h> #endif -#include "lua/luax.h" -#include "lua/luaopen_jin.h" +#include "lua/modules/luax.h" +#include "lua/modules/luaopen_jin.h" #include "libjin/jin.h" #include <Windows.h> |