aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules')
-rw-r--r--src/lua/modules/ai/je_lua_ai.cpp13
-rw-r--r--src/lua/modules/ai/je_lua_ai.h7
-rw-r--r--src/lua/modules/ai/je_lua_behavior_tree.cpp11
-rw-r--r--src/lua/modules/ai/je_lua_behavior_tree.h14
-rw-r--r--src/lua/modules/ai/je_lua_state_machine.cpp25
-rw-r--r--src/lua/modules/ai/je_lua_state_machine.h14
-rw-r--r--src/lua/modules/audio/audio.cpp123
-rw-r--r--src/lua/modules/audio/je_lua_audio.cpp135
-rw-r--r--src/lua/modules/audio/je_lua_audio.h6
-rw-r--r--src/lua/modules/audio/je_lua_source.cpp117
-rw-r--r--src/lua/modules/audio/je_lua_source.h16
-rw-r--r--src/lua/modules/audio/source.cpp116
-rw-r--r--src/lua/modules/bit/je_lua_bit.cpp (renamed from src/lua/modules/bit/bit.cpp)41
-rw-r--r--src/lua/modules/bit/je_lua_bit.h0
-rw-r--r--src/lua/modules/core/core.cpp46
-rw-r--r--src/lua/modules/core/je_lua_core.cpp46
-rw-r--r--src/lua/modules/core/je_lua_core.h0
-rw-r--r--src/lua/modules/event/je_lua_event.cpp (renamed from src/lua/modules/event/event.cpp)26
-rw-r--r--src/lua/modules/event/je_lua_event.h0
-rw-r--r--src/lua/modules/filesystem/je_lua_filesystem.cpp (renamed from src/lua/modules/filesystem/filesystem.cpp)41
-rw-r--r--src/lua/modules/filesystem/je_lua_filesystem.h0
-rw-r--r--src/lua/modules/graphics/bitmap.cpp113
-rw-r--r--src/lua/modules/graphics/canvas.cpp65
-rw-r--r--src/lua/modules/graphics/je_lua_bitmap.cpp114
-rw-r--r--src/lua/modules/graphics/je_lua_bitmap.h16
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.h16
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp (renamed from src/lua/modules/graphics/graphics.cpp)561
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.h0
-rw-r--r--src/lua/modules/graphics/je_lua_page.cpp69
-rw-r--r--src/lua/modules/graphics/je_lua_page.h22
-rw-r--r--src/lua/modules/graphics/je_lua_particle_system.cpp11
-rw-r--r--src/lua/modules/graphics/je_lua_particle_system.h0
-rw-r--r--src/lua/modules/graphics/je_lua_shader.cpp137
-rw-r--r--src/lua/modules/graphics/je_lua_shader.h16
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.cpp262
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.h24
-rw-r--r--src/lua/modules/graphics/je_lua_spritesheet.cpp54
-rw-r--r--src/lua/modules/graphics/je_lua_spritesheet.h21
-rw-r--r--src/lua/modules/graphics/je_lua_text.cpp32
-rw-r--r--src/lua/modules/graphics/je_lua_text.h16
-rw-r--r--src/lua/modules/graphics/je_lua_texture.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_texture.h16
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.h16
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.h16
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.cpp52
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.h21
-rw-r--r--src/lua/modules/graphics/page.cpp73
-rw-r--r--src/lua/modules/graphics/shader.cpp135
-rw-r--r--src/lua/modules/graphics/text.cpp32
-rw-r--r--src/lua/modules/graphics/texture.cpp65
-rw-r--r--src/lua/modules/graphics/texture_font.cpp67
-rw-r--r--src/lua/modules/graphics/ttf.cpp73
-rw-r--r--src/lua/modules/graphics/ttfData.cpp51
-rw-r--r--src/lua/modules/joypad/je_lua_joypad.cpp (renamed from src/lua/modules/joypad/joypad.cpp)12
-rw-r--r--src/lua/modules/joypad/je_lua_joypad.h0
-rw-r--r--src/lua/modules/keyboard/je_lua_keyboard.cpp (renamed from src/lua/modules/keyboard/keyboard.cpp)3
-rw-r--r--src/lua/modules/keyboard/je_lua_keyboard.h0
-rw-r--r--src/lua/modules/math/je_lua_math.cpp (renamed from src/lua/modules/math/math.cpp)14
-rw-r--r--src/lua/modules/math/je_lua_math.h0
-rw-r--r--src/lua/modules/mouse/je_lua_mouse.cpp (renamed from src/lua/modules/mouse/mouse.cpp)22
-rw-r--r--src/lua/modules/mouse/je_lua_mouse.h0
-rw-r--r--src/lua/modules/net/Buffer.cpp142
-rw-r--r--src/lua/modules/net/je_lua_buffer.cpp137
-rw-r--r--src/lua/modules/net/je_lua_buffer.h (renamed from src/lua/modules/net/Buffer.h)7
-rw-r--r--src/lua/modules/net/je_lua_net.cpp (renamed from src/lua/modules/net/net.cpp)42
-rw-r--r--src/lua/modules/net/je_lua_net.h0
-rw-r--r--src/lua/modules/net/je_lua_socket.cpp129
-rw-r--r--src/lua/modules/net/je_lua_socket.h16
-rw-r--r--src/lua/modules/net/socket.cpp129
-rw-r--r--src/lua/modules/thread/Thread.cpp252
-rw-r--r--src/lua/modules/thread/Thread.h94
-rw-r--r--src/lua/modules/thread/je_lua_thread.cpp248
-rw-r--r--src/lua/modules/thread/je_lua_thread.h93
-rw-r--r--src/lua/modules/time/je_lua_time.cpp71
-rw-r--r--src/lua/modules/time/je_lua_time.h0
-rw-r--r--src/lua/modules/time/je_lua_timer.cpp146
-rw-r--r--src/lua/modules/time/je_lua_timer.h20
-rw-r--r--src/lua/modules/time/time.cpp38
-rw-r--r--src/lua/modules/types.h25
82 files changed, 2899 insertions, 1968 deletions
diff --git a/src/lua/modules/ai/je_lua_ai.cpp b/src/lua/modules/ai/je_lua_ai.cpp
new file mode 100644
index 0000000..4afd625
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_ai.cpp
@@ -0,0 +1,13 @@
+#include "libjin/jin.h"
+
+using namespace JinEngine::AI;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_ai.h b/src/lua/modules/ai/je_lua_ai.h
new file mode 100644
index 0000000..036bc3f
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_ai.h
@@ -0,0 +1,7 @@
+#ifndef __JE_LUA_AI_H__
+#define __JE_LUA_AI_H__
+
+#include "je_lua_behavior_tree.h"
+#include "je_lua_state_machine.h"
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_behavior_tree.cpp b/src/lua/modules/ai/je_lua_behavior_tree.cpp
new file mode 100644
index 0000000..20e8e55
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_behavior_tree.cpp
@@ -0,0 +1,11 @@
+#include "libjin/jin.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_BehaviorTree = "Texture";
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_behavior_tree.h b/src/lua/modules/ai/je_lua_behavior_tree.h
new file mode 100644
index 0000000..083d12b
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_behavior_tree.h
@@ -0,0 +1,14 @@
+#ifndef __JE_LUA_BEHAVIOR_TREE_H__
+#define __JE_LUA_BEHAVIOR_TREE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_BehaviorTree;
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_state_machine.cpp b/src/lua/modules/ai/je_lua_state_machine.cpp
new file mode 100644
index 0000000..86ce7a5
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_state_machine.cpp
@@ -0,0 +1,25 @@
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+using namespace JinEngine::AI;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_StateMachine = "StateMachine";
+
+ LUA_IMPLEMENT int l_addEnterCallback(lua_State* L)
+ {
+ //StateMachine* sm;
+ //sm->addEnterListener("", [](void* p) -> void{
+
+ //
+ //});
+
+ return 0;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_state_machine.h b/src/lua/modules/ai/je_lua_state_machine.h
new file mode 100644
index 0000000..3c78f75
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_state_machine.h
@@ -0,0 +1,14 @@
+#ifndef __JE_LUA_STATE_MACHINE_H__
+#define __JE_LUA_STATE_MACHINE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_StateMachine;
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/audio/audio.cpp b/src/lua/modules/audio/audio.cpp
deleted file mode 100644
index 198323d..0000000
--- a/src/lua/modules/audio/audio.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Audio;
- using namespace JinEngine::Filesystem;
-
- typedef SDLAudio Audio;
- typedef SDLSource Source;
-
- static int l_init(lua_State* L)
- {
- Audio::Setting setting;
- setting.samplerate = 44100;
- setting.samples = 44100;
- if (!Audio::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_play(lua_State* L)
- {
- Audio::get()->play();
- return 0;
- }
-
- static int l_stop(lua_State* L)
- {
- Audio::get()->stop();
- return 0;
- }
-
- static int l_pause(lua_State* L)
- {
- Audio::get()->pause();
- return 0;
- }
-
- static int l_resume(lua_State* L)
- {
- Audio::get()->resume();
- return 0;
- }
-
- static int l_setVolume(lua_State* L)
- {
- float volume = luax_checknumber(L, 1);
- Audio::get()->setVolume(volume);
- return 0;
- }
-
- static int l_newSource(lua_State* L)
- {
- AssetDatabase* fs = AssetDatabase::get();
- const char* f = luax_checkstring(L, 1);
- Buffer b;
- if (!fs->exists(f))
- {
- error(L, "No such image %s", f);
- goto fail;
- }
- if (!fs->read(f, b))
- {
- error(L, "Failed to read source file %s", f);
- goto fail;
- }
- Source* src = Source::createSource((void*)&b, b.size());
- if (src == nullptr)
- {
- error(L, "Failed to decode source file %s", f);
- goto fail;
- }
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_AUDIO_SOURCE, sizeof(Proxy));
- proxy->bind(new Ref<Source>(src, JIN_AUDIO_SOURCE));
- return 1;
- fail:
- luax_pushnil(L);
- return 1;
- }
-
- static int l_destroy(lua_State* L)
- {
- Audio* audio = Audio::get();
- audio->quit();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "init", l_init },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "setVolume", l_setVolume },
- { "newSource", l_newSource },
- { "destroy", l_destroy },
- { 0, 0 }
- };
-
- extern int luaopen_Source(lua_State* L);
-
- int luaopen_audio(lua_State* L)
- {
- luaopen_Source(L);
-
- luax_newlib(L, f);
-
- return 1;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_audio.cpp b/src/lua/modules/audio/je_lua_audio.cpp
new file mode 100644
index 0000000..50c5268
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_audio.cpp
@@ -0,0 +1,135 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_source.h"
+
+using namespace JinEngine::Audio;
+using namespace JinEngine::Audio::SDL;
+using namespace JinEngine::Filesystem;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ typedef SDLAudio Audio;
+ typedef SDLSource Source;
+
+ struct
+ {
+ bool initialized = false;
+ } context;
+
+ LUA_IMPLEMENT int l_init(lua_State* L)
+ {
+ if (context.initialized)
+ {
+ // Already initialized.
+ luax_pushboolean(L, true);
+ return 1;
+ }
+ Audio::Setting setting;
+ setting.samplerate = 44100;
+ setting.samples = 44100;
+ context.initialized = Audio::get()->init(&setting);
+ if (!context.initialized)
+ {
+ luax_error(L, "could not init audio");
+ luax_pushboolean(L, false);
+ return 1;
+ }
+ luax_pushboolean(L, true);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_play(lua_State* L)
+ {
+ Audio::get()->play();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_stop(lua_State* L)
+ {
+ Audio::get()->stop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ Audio::get()->pause();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_resume(lua_State* L)
+ {
+ Audio::get()->resume();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setVolume(lua_State* L)
+ {
+ float volume = luax_checknumber(L, 1);
+ Audio::get()->setVolume(volume);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newSource(lua_State* L)
+ {
+ AssetDatabase* fs = AssetDatabase::get();
+ const char* f = luax_checkstring(L, 1);
+ Buffer b;
+ try
+ {
+ if (!fs->exists(f))
+ throw Exception("No such source file %s.", f);
+ fs->read(f, b);
+ }
+ catch (Exception& e)
+ {
+ error(L, "Failed to read source file %s", f);
+ luax_pushnil(L);
+ return 1;
+ }
+ Source* src = Source::createSource((void*)&b, b.size());
+ if (src == nullptr)
+ {
+ error(L, "Failed to decode source file %s", f);
+ luax_pushnil(L);
+ return 1;
+ }
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Source);
+ proxy->bind(new Shared<Source>(src, Jin_Lua_Source));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_destroy(lua_State* L)
+ {
+ Audio* audio = Audio::get();
+ audio->quit();
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_audio(lua_State* L)
+ {
+ luaopen_Source(L);
+
+ luaL_Reg f[] = {
+ { "init", l_init },
+ { "play", l_play },
+ { "stop", l_stop },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "setVolume", l_setVolume },
+ { "newSource", l_newSource },
+ { "destroy", l_destroy },
+ { 0, 0 }
+ };
+
+ luax_newlib(L, f);
+
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_audio.h b/src/lua/modules/audio/je_lua_audio.h
new file mode 100644
index 0000000..fa66392
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_audio.h
@@ -0,0 +1,6 @@
+#ifndef __JE_LUA_AUDIO_H__
+#define __JE_LUA_AUDIO_H__
+
+#include "je_lua_audio.h"
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_source.cpp b/src/lua/modules/audio/je_lua_source.cpp
new file mode 100644
index 0000000..e152847
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_source.cpp
@@ -0,0 +1,117 @@
+#include "libjin/jin.h"
+#include "lua/modules/luax.h"
+#include "lua/common/je_lua_common.h"
+
+
+using namespace JinEngine::Audio;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Source = "Source";
+
+ typedef Shared<Source>& SharedSource;
+
+ LUA_IMPLEMENT inline SharedSource checkSource(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Source);
+ return proxy->getShared<Source>();
+ }
+
+ LUA_IMPLEMENT int l_play(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->play();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_stop(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->stop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->pause();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rewind(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->rewind();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_resume(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->resume();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_isStop(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ bool isStop = shared->isStopped();
+ luax_pushboolean(L, isStop);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_isPaused(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ bool isPaused = shared->isPaused();
+ luax_pushboolean(L, isPaused);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_setVolume(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ float volume = luax_checknumber(L, 2);
+ shared->setVolume(volume);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setLoop(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ bool loop = luax_checkbool(L, 2);
+ shared->setLoop(loop);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Source);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Source(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "play", l_play },
+ { "stop", l_stop },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "rewind", l_rewind },
+ { "isStop", l_isStop },
+ { "isPaused", l_isPaused },
+ { "setVolume", l_setVolume },
+ { "setLoop", l_setLoop },
+ { 0, 0 }
+ };
+
+ luax_newtype(L, Jin_Lua_Source, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_source.h b/src/lua/modules/audio/je_lua_source.h
new file mode 100644
index 0000000..f7e6b48
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_source.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_SOURCE_H__
+#define __JE_LUA_SOURCE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Source;
+
+ void luaopen_Source(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/audio/source.cpp b/src/lua/modules/audio/source.cpp
deleted file mode 100644
index bf43ceb..0000000
--- a/src/lua/modules/audio/source.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-#include "libjin/jin.h"
-#include "lua/modules/luax.h"
-#include "lua/common/common.h"
-#include "lua/modules/types.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Audio;
-
- typedef Ref<Source>& SourceRef;
-
- static inline SourceRef checkSource(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE);
- return proxy->getRef<Source>();
- }
-
- static int l_play(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->play();
- return 0;
- }
-
- static int l_stop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->stop();
- return 0;
- }
-
- static int l_pause(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->pause();
- return 0;
- }
-
- static int l_rewind(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->rewind();
- return 0;
- }
-
- static int l_resume(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->resume();
- return 0;
- }
-
- static int l_isStop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool isStop = ref->isStopped();
- luax_pushboolean(L, isStop);
- return 1;
- }
-
- static int l_isPaused(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool isPaused = ref->isPaused();
- luax_pushboolean(L, isPaused);
- return 1;
- }
-
- static int l_setVolume(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- float volume = luax_checknumber(L, 2);
- ref->setVolume(volume);
- return 0;
- }
-
- static int l_setLoop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool loop = luax_checkbool(L, 2);
- ref->setLoop(loop);
- return 0;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "rewind", l_rewind },
- { "isStop", l_isStop },
- { "isPaused", l_isPaused },
- { "setVolume", l_setVolume },
- { "setLoop", l_setLoop },
- { 0, 0 }
- };
-
- int luaopen_Source(lua_State* L)
- {
- luax_newtype(L, JIN_AUDIO_SOURCE, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/bit/bit.cpp b/src/lua/modules/bit/je_lua_bit.cpp
index cedd60a..fdd0ae0 100644
--- a/src/lua/modules/bit/bit.cpp
+++ b/src/lua/modules/bit/je_lua_bit.cpp
@@ -1,5 +1,7 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
+
#include <cstdlib>
namespace JinEngine
@@ -7,7 +9,7 @@ namespace JinEngine
namespace Lua
{
- static int l_and(lua_State* L)
+ LUA_IMPLEMENT int l_and(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -15,7 +17,7 @@ namespace JinEngine
return 1;
}
- static int l_or(lua_State* L)
+ LUA_IMPLEMENT int l_or(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -23,7 +25,7 @@ namespace JinEngine
return 1;
}
- static int l_xor(lua_State* L)
+ LUA_IMPLEMENT int l_xor(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -31,14 +33,14 @@ namespace JinEngine
return 1;
}
- static int l_not(lua_State* L)
+ LUA_IMPLEMENT int l_not(lua_State* L)
{
int n = luax_checkinteger(L, 1);
luax_pushinteger(L, ~n);
return 1;
}
- static int l_lshift(lua_State* L)
+ LUA_IMPLEMENT int l_lshift(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -46,7 +48,7 @@ namespace JinEngine
return 1;
}
- static int l_rshift(lua_State* L)
+ LUA_IMPLEMENT int l_rshift(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -54,7 +56,7 @@ namespace JinEngine
return 1;
}
- static int l_include(lua_State* L)
+ LUA_IMPLEMENT int l_include(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -62,19 +64,20 @@ namespace JinEngine
return 1;
}
- static const luaL_Reg f[] = {
- { "bAnd", l_and },
- { "bOr" , l_or },
- { "bXor", l_xor },
- { "bNot", l_not },
- { "bLs", l_lshift },
- { "bRs", l_rshift },
- { "bInc", l_include },
- { 0, 0 }
- };
-
- int luaopen_bit(lua_State* L)
+
+ LUA_EXPORT int luaopen_bit(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "bAnd", l_and },
+ { "bOr" , l_or },
+ { "bXor", l_xor },
+ { "bNot", l_not },
+ { "bLs", l_lshift },
+ { "bRs", l_rshift },
+ { "bInc", l_include },
+ { 0, 0 }
+ };
+
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/bit/je_lua_bit.h b/src/lua/modules/bit/je_lua_bit.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/bit/je_lua_bit.h
diff --git a/src/lua/modules/core/core.cpp b/src/lua/modules/core/core.cpp
deleted file mode 100644
index a576bec..0000000
--- a/src/lua/modules/core/core.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "lua/modules/luax.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Core;
-
- static int l_running(lua_State* L)
- {
- static Game* game = Game::get();
- bool running = game->running();
- luax_pushboolean(L, running);
- return 1;
- }
-
- static int l_stop(lua_State* L)
- {
- Game::get()->stop();
- return 0;
- }
-
- static int l_quit(lua_State* L)
- {
- Game::get()->quit();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "running", l_running },
- { "stop", l_stop },
- { "quit", l_quit },
- { 0, 0 }
- };
-
- int luaopen_core(lua_State* L)
- {
- luax_newlib(L, f);
-
- return 1;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/core/je_lua_core.cpp b/src/lua/modules/core/je_lua_core.cpp
new file mode 100644
index 0000000..f5b06c3
--- /dev/null
+++ b/src/lua/modules/core/je_lua_core.cpp
@@ -0,0 +1,46 @@
+#include "lua/common/je_lua_common.h"
+#include "lua/modules/luax.h"
+#include "libjin/jin.h"
+
+using namespace JinEngine::Game;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ LUA_IMPLEMENT int l_running(lua_State* L)
+ {
+ static Application* app = Application::get();
+ bool running = app->running();
+ luax_pushboolean(L, running);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_stop(lua_State* L)
+ {
+ Application::get()->stop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_quit(lua_State* L)
+ {
+ Application::get()->quit();
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_core(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "running", l_running },
+ { "stop", l_stop },
+ { "quit", l_quit },
+ { 0, 0 }
+ };
+ luax_newlib(L, f);
+
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/core/je_lua_core.h b/src/lua/modules/core/je_lua_core.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/core/je_lua_core.h
diff --git a/src/lua/modules/event/event.cpp b/src/lua/modules/event/je_lua_event.cpp
index 9f565d0..82ba385 100644
--- a/src/lua/modules/event/event.cpp
+++ b/src/lua/modules/event/je_lua_event.cpp
@@ -1,21 +1,22 @@
/**
* Event module
*/
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
+using namespace JinEngine;
+using namespace JinEngine::Input;
+
namespace JinEngine
{
namespace Lua
{
- using namespace JinEngine;
- using namespace JinEngine::Input;
-
/**
* Load event poll, return a iterator(a table).
*/
- static int l_event_poll(lua_State *L)
+ LUA_IMPLEMENT int l_event_poll(lua_State *L)
{
/* table to store events */
luax_newtable(L);
@@ -100,10 +101,9 @@ namespace JinEngine
case EventType::CONTROLLERAXISMOTION:
-
default:
- /* ignore other events */
- luax_pop(L, 1); // pop table out
+ // Ignore oter events and pop up the event table.
+ luax_pop(L, 1);
goto poll;
break;
}
@@ -111,18 +111,18 @@ namespace JinEngine
}
return 1;
}
-
- static const luaL_Reg f[] = {
- { "poll", l_event_poll },
- { 0, 0 }
- };
/**
* load event module
*/
- int luaopen_event(lua_State* L)
+ LUA_EXPORT int luaopen_event(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "poll", l_event_poll },
+ { 0, 0 }
+ };
luax_newlib(L, f);
+
return 1;
}
diff --git a/src/lua/modules/event/je_lua_event.h b/src/lua/modules/event/je_lua_event.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/event/je_lua_event.h
diff --git a/src/lua/modules/filesystem/filesystem.cpp b/src/lua/modules/filesystem/je_lua_filesystem.cpp
index 7466ce8..6245ba8 100644
--- a/src/lua/modules/filesystem/filesystem.cpp
+++ b/src/lua/modules/filesystem/je_lua_filesystem.cpp
@@ -1,3 +1,4 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
#include <string>
@@ -9,25 +10,25 @@ namespace JinEngine
namespace Lua
{
- static struct
+ LUA_IMPLEMENT struct
{
AssetDatabase* fs;
} context;
- static int l_init(lua_State* L)
+ LUA_IMPLEMENT int l_init(lua_State* L)
{
context.fs = AssetDatabase::get();
return 0;
}
- static int l_mount(lua_State* L)
+ LUA_IMPLEMENT int l_mount(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
context.fs->mount(path);
return 0;
}
- static int l_exist(lua_State * L)
+ LUA_IMPLEMENT int l_exist(lua_State * L)
{
const char* path = luax_checkstring(L, 1);
int r = context.fs->exists(path);
@@ -35,7 +36,7 @@ namespace JinEngine
return 1;
}
- static int l_isDir(lua_State* L)
+ LUA_IMPLEMENT int l_isDir(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
int r = context.fs->isDir(path);
@@ -43,7 +44,7 @@ namespace JinEngine
return 1;
}
- static int l_isFile(lua_State* L)
+ LUA_IMPLEMENT int l_isFile(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
int r = context.fs->isFile(path);
@@ -51,7 +52,7 @@ namespace JinEngine
return 1;
}
- static int loadbuffer(lua_State* L)
+ LUA_IMPLEMENT int loadbuffer(lua_State* L)
{
const char* filename = lua_tostring(L, -1);
Buffer bf;
@@ -60,7 +61,7 @@ namespace JinEngine
return 1;
}
- static int loader(lua_State* L)
+ LUA_IMPLEMENT int loader(lua_State* L)
{
const char * filename = lua_tostring(L, -1);
@@ -107,7 +108,7 @@ namespace JinEngine
return 1;
}
- static int l_read(lua_State* L)
+ LUA_IMPLEMENT int l_read(lua_State* L)
{
AssetDatabase* fs = context.fs;
const char* file = luax_checkstring(L, 1);
@@ -119,20 +120,20 @@ namespace JinEngine
return 2;
}
- static const luaL_Reg f[] = {
- { "init", l_init },
- { "mount", l_mount },
- { "isDirectory", l_isDir },
- { "isFile", l_isFile },
- { "exist", l_exist },
- { "read", l_read },
- { 0, 0 }
- };
-
- int luaopen_filesystem(lua_State* L)
+ LUA_EXPORT int luaopen_filesystem(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "init", l_init },
+ { "mount", l_mount },
+ { "isDirectory", l_isDir },
+ { "isFile", l_isFile },
+ { "exist", l_exist },
+ { "read", l_read },
+ { 0, 0 }
+ };
luax_newlib(L, f);
luax_registersearcher(L, loader, 1);
+
return 0;
}
diff --git a/src/lua/modules/filesystem/je_lua_filesystem.h b/src/lua/modules/filesystem/je_lua_filesystem.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/filesystem/je_lua_filesystem.h
diff --git a/src/lua/modules/graphics/bitmap.cpp b/src/lua/modules/graphics/bitmap.cpp
deleted file mode 100644
index 13517f9..0000000
--- a/src/lua/modules/graphics/bitmap.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Bitmap>& BitmapRef;
-
- static inline BitmapRef checkBitmap(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
- return proxy->getRef<Bitmap>();
- }
-
- static int l_gc(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- ref.release();
- return 0;
- }
-
- static int l_getWidth(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int w = ref->getWidth();
- luax_pushinteger(L, w);
- return 1;
- }
-
- static int l_getHeight(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int h = ref->getHeight();
- luax_pushinteger(L, h);
- return 1;
- }
-
- static int l_getSize(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int w = ref->getWidth();
- int h = ref->getHeight();
- luax_pushinteger(L, w);
- luax_pushinteger(L, h);
- return 2;
- }
-
- static int l_getPixel(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int x = luax_checkinteger(L, 2);
- int y = luax_checkinteger(L, 3);
- Color col = ref->getPixel(x, y);
- luax_pushinteger(L, col.r);
- luax_pushinteger(L, col.g);
- luax_pushinteger(L, col.b);
- luax_pushinteger(L, col.a);
- return 4;
- }
-
- static int l_setPixel(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int x = luax_checkinteger(L, 2);
- int y = luax_checkinteger(L, 3);
- if (!luax_istable(L, 4))
- {
- luax_typerror(L, 4, "table");
- return 1;
- }
- unsigned int r = luax_rawgetnumber(L, 4, 1);
- unsigned int g = luax_rawgetnumber(L, 4, 2);
- unsigned int b = luax_rawgetnumber(L, 4, 3);
- unsigned int a = luax_rawgetnumber(L, 4, 4);
- ref->setPixel(Color(r, g, b, a), x, y);
- return 0;
- }
-
- static int l_clone(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- Bitmap* bitmap = ref.getObject();
- Bitmap* b = Bitmap::clone(bitmap);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
- proxy->bind(new Ref<Bitmap>(b, JIN_GRAPHICS_BITMAP));
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { "getPixel", l_getPixel },
- { "setPixel", l_setPixel },
- { "clone", l_clone },
- { 0, 0 }
- };
-
- int luaopen_Bitmap(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_BITMAP, f);
- return 0;
- }
-
- } // graphics
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/canvas.cpp b/src/lua/modules/graphics/canvas.cpp
deleted file mode 100644
index e49e209..0000000
--- a/src/lua/modules/graphics/canvas.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Canvas>& CanvasRef;
-
- static inline CanvasRef checkCanvas(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- return proxy->getRef<Canvas>();
- }
-
- static int l_getWidth(lua_State* L)
- {
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getWidth());
- return 1;
- }
-
- static int l_getHeight(lua_State* L)
- {
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getHeight());
- return 1;
- }
-
- static int l_getSize(lua_State* L)
- {
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getWidth());
- luax_pushnumber(L, ref->getHeight());
- return 2;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { 0, 0 }
- };
-
- int luaopen_Canvas(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_CANVAS, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_bitmap.cpp b/src/lua/modules/graphics/je_lua_bitmap.cpp
new file mode 100644
index 0000000..6b7655f
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_bitmap.cpp
@@ -0,0 +1,114 @@
+#include "lua/common/je_lua_common.h"
+#include "lua/modules/luax.h"
+
+#include "libjin/jin.h"
+#include "je_lua_bitmap.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Bitmap = "Bitmap";
+
+ typedef Shared<Bitmap>& SharedBitmap;
+
+ LUA_IMPLEMENT inline SharedBitmap checkBitmap(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Bitmap);
+ return proxy->getShared<Bitmap>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ shared.release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int w = shared->getWidth();
+ luax_pushinteger(L, w);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int h = shared->getHeight();
+ luax_pushinteger(L, h);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int w = shared->getWidth();
+ int h = shared->getHeight();
+ luax_pushinteger(L, w);
+ luax_pushinteger(L, h);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getPixel(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int x = luax_checkinteger(L, 2);
+ int y = luax_checkinteger(L, 3);
+ Color col = shared->getPixel(x, y);
+ luax_pushinteger(L, col.r);
+ luax_pushinteger(L, col.g);
+ luax_pushinteger(L, col.b);
+ luax_pushinteger(L, col.a);
+ return 4;
+ }
+
+ LUA_IMPLEMENT int l_setPixel(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int x = luax_checkinteger(L, 2);
+ int y = luax_checkinteger(L, 3);
+ if (!luax_istable(L, 4))
+ {
+ luax_typerror(L, 4, "table");
+ return 1;
+ }
+ unsigned int r = luax_rawgetnumber(L, 4, 1);
+ unsigned int g = luax_rawgetnumber(L, 4, 2);
+ unsigned int b = luax_rawgetnumber(L, 4, 3);
+ unsigned int a = luax_rawgetnumber(L, 4, 4);
+ shared->setPixel(Color(r, g, b, a), x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_clone(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ Bitmap* bitmap = shared.getObject();
+ Bitmap* b = Bitmap::clone(bitmap);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap);
+ proxy->bind(new Shared<Bitmap>(b, Jin_Lua_Bitmap));
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_Bitmap(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { "getPixel", l_getPixel },
+ { "setPixel", l_setPixel },
+ { "clone", l_clone },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Bitmap, f);
+ }
+
+ } // namespace Graphics
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_bitmap.h b/src/lua/modules/graphics/je_lua_bitmap.h
new file mode 100644
index 0000000..b463d83
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_bitmap.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_BITMAP_H__
+#define __JE_LUA_BITMAP_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Bitmap;
+
+ void luaopen_Bitmap(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_canvas.cpp b/src/lua/modules/graphics/je_lua_canvas.cpp
new file mode 100644
index 0000000..f7bd650
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_canvas.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_canvas.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Canvas = "Canvas";
+
+ typedef Shared<Canvas>& SharedCanvas;
+
+ LUA_IMPLEMENT inline SharedCanvas checkCanvas(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ return proxy->getShared<Canvas>();
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getWidth());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
+ {
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getHeight());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getWidth());
+ luax_pushnumber(L, shared->getHeight());
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Canvas(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Canvas, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_canvas.h b/src/lua/modules/graphics/je_lua_canvas.h
new file mode 100644
index 0000000..d1fa885
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_canvas.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_CANVAS_H__
+#define __JE_LUA_CANVAS_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Canvas;
+
+ void luaopen_Canvas(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 8b2d7cd..ce569d0 100644
--- a/src/lua/modules/graphics/graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -3,14 +3,27 @@
#include "libjin/jin.h"
#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
+
+#include "lua/common/je_lua_common.h"
+
+#include "je_lua_canvas.h"
+#include "je_lua_sprite.h"
+#include "je_lua_spritesheet.h"
+#include "je_lua_bitmap.h"
+#include "je_lua_ttf.h"
+#include "je_lua_ttf_data.h"
+#include "je_lua_texture.h"
+#include "je_lua_shader.h"
+#include "je_lua_text.h"
+#include "je_lua_texture_font.h"
+#include "je_lua_page.h"
using namespace std;
using namespace JinEngine;
using namespace JinEngine::Graphics;
-using JinEngine::Filesystem::AssetDatabase;
-using JinEngine::Filesystem::Buffer;
+using namespace JinEngine::Graphics::Fonts;
+using namespace JinEngine::Graphics::Shaders;
+using namespace JinEngine::Filesystem;
namespace JinEngine
{
@@ -18,59 +31,52 @@ namespace JinEngine
{
#include "../../resources/font.ttf.h"
-
+
static struct
{
Color curRenderColor;
Color curClearColor;
Font* curFont = nullptr;
Font* defaultFont = nullptr;
+ bool initialized = false;
} context;
- static int l_init(lua_State* L)
+ LUA_IMPLEMENT int l_init(lua_State* L)
{
+ if (context.initialized)
+ {
+ luax_pushboolean(L, true);
+ return 1;
+ }
+
Window* wnd = Window::get();
Window::Setting setting;
setting.width = luax_getfieldinteger(L, 1, "width");
setting.height = luax_getfieldinteger(L, 1, "height");
setting.title = luax_getfieldstring(L, 1, "title");
+ setting.icon = luax_getfieldstring(L, 1, "icon");
setting.vsync = luax_getfieldbool(L, 1, "vsync");
setting.fullscreen = luax_getfieldbool(L, 1, "fullscreen");
setting.resizable = luax_getfieldbool(L, 1, "resizable");
- if (!wnd->init(&setting))
+ context.initialized = wnd->init(&setting);
+ if (!context.initialized)
{
- luax_pushboolean(L, false);
+ luax_pushboolean(L, context.initialized);
return 1;
}
- {
- /* load default font */
- Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap));
- const Color* pixels = bitmap->getPixels();
- ofstream f = ofstream();
- f.open("font.pixels", ios_base::app);
- for (int y = 0; y < bitmap->getHeight(); ++y)
- {
- for (int x = 0; x < bitmap->getWidth(); ++x)
- {
- Color c = pixels[x + y * bitmap->getWidth()];
- f << (int)c.r << ",";
- f << (int)c.g << ",";
- f << (int)c.b << ",";
- f << (int)c.a << ",";
- }
- }
-
- TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight());
- context.defaultFont = tf;
- delete bitmap;
- }
- context.curFont = context.defaultFont;
-
- luax_pushboolean(L, true);
+
+ /* load default font */
+ Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap));
+ TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight());
+ delete bitmap;
+ context.defaultFont = tf;
+ context.curFont = tf;
+
+ luax_pushboolean(L, context.initialized);
return 1;
}
- static int l_setTitle(lua_State* L)
+ LUA_IMPLEMENT int l_setTitle(lua_State* L)
{
Window* wnd = Window::get();
const char* title = luax_checkstring(L, 1);
@@ -78,14 +84,28 @@ namespace JinEngine
return 0;
}
- static int l_destroy(lua_State* L)
+ LUA_IMPLEMENT int l_destroy(lua_State* L)
{
Window* wnd = Window::get();
wnd->quit();
return 0;
}
-
- static int l_getSize(lua_State* L)
+
+ LUA_IMPLEMENT int l_showWindow(lua_State* L)
+ {
+ Window* wnd = Window::get();
+ wnd->show();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_hideWindow(lua_State* L)
+ {
+ Window* wnd = Window::get();
+ wnd->hide();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getW());
@@ -93,21 +113,21 @@ namespace JinEngine
return 2;
}
- static int l_getWidth(lua_State* L)
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getW());
return 1;
}
- static int l_getHeight(lua_State* L)
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getH());
return 1;
}
- static int l_newBitmap(lua_State* L)
+ LUA_IMPLEMENT int l_newBitmap(lua_State* L)
{
Bitmap* bitmap = nullptr;
if (luax_gettop(L) == 2)
@@ -120,55 +140,82 @@ namespace JinEngine
{
int w = luax_checkinteger(L, 1);
int h = luax_checkinteger(L, 2);
- if (!luax_istable(L, 3))
+ if (luax_istable(L, 3))
{
- luax_typerror(L, 3, "table");
+ unsigned int r = luax_rawgetnumber(L, 3, 1);
+ unsigned int g = luax_rawgetnumber(L, 3, 2);
+ unsigned int b = luax_rawgetnumber(L, 3, 3);
+ unsigned int a = luax_rawgetnumber(L, 3, 4);
+ bitmap = Bitmap::createBitmap(w, h, Color(r, g, b, a));
+ }
+ else if (luax_isfunction(L, 3))
+ {
+ std::function<Color(int, int, int, int)> drawer = [=](int w, int h, int x, int y)->Color{
+ luax_pushvalue(L, 3);
+ luax_pushnumber(L, w);
+ luax_pushnumber(L, h);
+ luax_pushnumber(L, x);
+ luax_pushnumber(L, y);
+ // Call drawer function.
+ luax_call(L, 4, 1);
+ // Get result color.
+ if (!luax_istable(L, -1))
+ luax_error(L, "Return value of bitmap drawer is wrong, should be a color table.");
+ Color c;
+ c.r = luax_rawgetnumberthenpop(L, -1, 1);
+ c.g = luax_rawgetnumberthenpop(L, -1, 2);
+ c.b = luax_rawgetnumberthenpop(L, -1, 3);
+ c.a = luax_rawgetnumberthenpop(L, -1, 4);
+ // Pop return value.
+ luax_pop(L, 1);
+ return c;
+ };
+ bitmap = Bitmap::createBitmap(w, h, drawer);
+ }
+ else
+ {
+ luax_typerror(L, 3, "color table or color setter");
return 1;
}
- unsigned int r = luax_rawgetnumber(L, 3, 1);
- unsigned int g = luax_rawgetnumber(L, 3, 2);
- unsigned int b = luax_rawgetnumber(L, 3, 3);
- unsigned int a = luax_rawgetnumber(L, 3, 4);
- bitmap = Bitmap::createBitmap(w, h, Color(r, g, b, a));
}
else
{
const char* f = luax_checkstring(L, 1);
AssetDatabase* fs = AssetDatabase::get();
- if (!fs->exists(f))
+ Buffer b;
+ try
{
- error(L, "No such image file %s", f);
- goto fail;
+ if (!fs->exists(f))
+ throw Exception("No such image file %s.", f);
+ fs->read(f, b);
}
- Buffer b;
- if (!fs->read(f, b))
+ catch (Exception& e)
{
error(L, "Failed to read image %s", f);
- goto fail;
+ luax_pushnil(L);
+ return 1;
}
bitmap = Bitmap::createBitmap(&b, b.size());
if (bitmap == nullptr)
{
error(L, "Failed to decode image file %s", f);
- goto fail;
+ luax_pushnil(L);
+ return 1;
}
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
- proxy->bind(new Ref<Bitmap>(bitmap, JIN_GRAPHICS_BITMAP));
- return 1;
- fail:
- luax_pushnil(L);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap);
+ proxy->bind(new Shared<Bitmap>(bitmap, Jin_Lua_Bitmap));
return 1;
}
/* jin.graphics.newTexture(bitmap) */
- static int l_newTexture(lua_State* L)
+ LUA_IMPLEMENT int l_newTexture(lua_State* L)
{
Texture* texture = nullptr;
- if (luax_istype(L, 1, JIN_GRAPHICS_BITMAP))
+ if (luax_istype(L, 1, Jin_Lua_Bitmap))
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
- Ref<Bitmap>& refBitmap = p->getRef<Bitmap>();
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Bitmap);
+ Shared<Bitmap>& refBitmap = p->getShared<Bitmap>();
Bitmap* bitmap = refBitmap.getObject();
texture = Texture::createTexture(bitmap);
}
@@ -177,12 +224,12 @@ namespace JinEngine
const char* path = luax_checkstring(L, 1);
texture = Texture::createTexture(path);
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTURE, sizeof(Proxy));
- proxy->bind(new Ref<Texture>(texture, JIN_GRAPHICS_TEXTURE));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Texture);
+ proxy->bind(new Shared<Texture>(texture, Jin_Lua_Texture));
return 1;
}
- static int l_newShader(lua_State* L)
+ LUA_IMPLEMENT int l_newShader(lua_State* L)
{
const char* program = luax_checkstring(L, 1);
Shader* jsl = Shader::createShader(program);
@@ -192,18 +239,18 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
- proxy->bind(new Ref<Shader>(jsl, JIN_GRAPHICS_SHADER));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader);
+ proxy->bind(new Shared<Shader>(jsl, Jin_Lua_Shader));
return 1;
}
- static int l_newShaderf(lua_State* L)
+ LUA_IMPLEMENT int l_newShaderf(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
AssetDatabase* fs = AssetDatabase::get();
if (!fs->exists(path))
{
- error(L, "No such shader file %s\n", path);
+ error(L, "No such shader file \"%s\"", path);
luax_pushnil(L);
return 1;
}
@@ -216,28 +263,28 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
- proxy->bind(new Ref<Shader>(jsl, JIN_GRAPHICS_SHADER));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader);
+ proxy->bind(new Shared<Shader>(jsl, Jin_Lua_Shader));
return 1;
}
- static int l_newCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_newCanvas(lua_State* L)
{
int w = luax_checknumber(L, 1);
int h = luax_checknumber(L, 2);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_CANVAS, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Canvas);
Canvas* cvs = Canvas::createCanvas(w, h);
- proxy->bind(new Ref<Canvas>(cvs, JIN_GRAPHICS_CANVAS));
+ proxy->bind(new Shared<Canvas>(cvs, Jin_Lua_Canvas));
return 1;
}
- static int l_clear(lua_State* L)
+ LUA_IMPLEMENT int l_clear(lua_State* L)
{
glClear(GL_COLOR_BUFFER_BIT);
return 0;
}
- static int l_setClearColor(lua_State* L)
+ LUA_IMPLEMENT int l_setClearColor(lua_State* L)
{
if (luax_gettop(L) == 0)
{
@@ -257,15 +304,15 @@ namespace JinEngine
return 0;
}
- static int l_present(lua_State* L)
+ LUA_IMPLEMENT int l_present(lua_State* L)
{
Window::get()->swapBuffers();
return 0;
}
- static void l_draw_texture(lua_State* L)
+ LUA_IMPLEMENT void l_draw_texture(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
+ if (!luax_istype(L, 1, Jin_Lua_Texture))
return;
int x = luax_optnumber(L, 2, 0);
int y = luax_optnumber(L, 3, 0);
@@ -275,13 +322,13 @@ namespace JinEngine
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Texture>& tex = proxy->getRef<Texture>();
- tex->draw(x, y, sx, sy, r, ox, oy);
+ Shared<Texture>& tex = proxy->getShared<Texture>();
+ tex->render(x, y, sx, sy, r, ox, oy);
}
- static void l_draw_canvas(lua_State* L)
+ LUA_IMPLEMENT void l_draw_canvas(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
+ if (!luax_istype(L, 1, Jin_Lua_Canvas))
return;
int x = luax_optnumber(L, 2, 0);
int y = luax_optnumber(L, 3, 0);
@@ -291,14 +338,14 @@ namespace JinEngine
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Canvas>& p = proxy->getRef<Canvas>();
- p->draw(x, y, sx, sy, r, ox, oy);
+ Shared<Canvas>& p = proxy->getShared<Canvas>();
+ p->render(x, y, sx, sy, r, ox, oy);
}
/* jin.graphics.draw(text, font, x, y) */
- static void l_draw_text(lua_State* L)
+ LUA_IMPLEMENT void l_draw_text(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_TEXT))
+ if (!luax_istype(L, 1, Jin_Lua_Text))
return;
Proxy* p = (Proxy*)luax_toudata(L, 1);
Text* text = p->getObject<Text>();
@@ -307,12 +354,12 @@ namespace JinEngine
int spacing = luax_optnumber(L, 6, 0);
Font* font = nullptr;
Proxy* p2 = (Proxy*)luax_toudata(L, 2);
- if (luax_istype(L, 2, JIN_GRAPHICS_TEXTUREFONT))
+ if (luax_istype(L, 2, Jin_Lua_TextureFont))
{
TextureFont* tf = p2->getObject<TextureFont>();
font = tf;
}
- else if (luax_istype(L, 2, JIN_GRAPHICS_TTF))
+ else if (luax_istype(L, 2, Jin_Lua_TTF))
{
TTF* ttf = p2->getObject<TTF>();
font = ttf;
@@ -322,31 +369,31 @@ namespace JinEngine
font = context.defaultFont;
}
int lineheight = luax_optnumber(L, 5, font->getFontSize());
- font->print(*text, x, y, lineheight, spacing);
+ font->render(*text, x, y, lineheight, spacing);
}
/* jin.graphics.draw(page, x, y) */
- static void l_draw_page(lua_State* L)
+ LUA_IMPLEMENT void l_draw_page(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_PAGE))
+ if (!luax_istype(L, 1, Jin_Lua_Page))
return;
int x = luax_optnumber(L, 2, 0);
int y = luax_optnumber(L, 3, 0);
Proxy* p = (Proxy*)luax_toudata(L, 1);
Page* page = p->getObject<Page>();
Font* font = page->font;
- font->print(page, x, y);
+ font->render(page, x, y);
}
- static int l_draw(lua_State* L)
+ LUA_IMPLEMENT int l_draw(lua_State* L)
{
- if (luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
+ if (luax_istype(L, 1, Jin_Lua_Texture))
l_draw_texture(L);
- else if (luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
+ else if (luax_istype(L, 1, Jin_Lua_Canvas))
l_draw_canvas(L);
- else if (luax_istype(L, 1, JIN_GRAPHICS_TEXT))
+ else if (luax_istype(L, 1, Jin_Lua_Text))
l_draw_text(L);
- else if (luax_istype(L, 1, JIN_GRAPHICS_PAGE))
+ else if (luax_istype(L, 1, Jin_Lua_Page))
l_draw_page(L);
else
{
@@ -357,7 +404,7 @@ namespace JinEngine
}
// draw(tex, quad, x, y, sx, sy, r, ax, ay)
- static int l_drawq(lua_State* L)
+ LUA_IMPLEMENT int l_drawq(lua_State* L)
{
if (!luax_istable(L, 2))
{
@@ -378,17 +425,17 @@ namespace JinEngine
float ox = luax_optnumber(L, 8, 0);
float oy = luax_optnumber(L, 9, 0);
- if (luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
+ if (luax_istype(L, 1, Jin_Lua_Texture))
{
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Texture>& tex = proxy->getRef<Texture>();
- tex->draw(q, x, y, sx, sy, r, ox, oy);
+ Shared<Texture>& tex = proxy->getShared<Texture>();
+ tex->render(q, x, y, sx, sy, r, ox, oy);
}
- else if (luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
+ else if (luax_istype(L, 1, Jin_Lua_Canvas))
{
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Canvas>& p = proxy->getRef<Canvas>();
- p->draw(q, x, y, sx, sy, r, ox, oy);
+ Shared<Canvas>& p = proxy->getShared<Canvas>();
+ p->render(q, x, y, sx, sy, r, ox, oy);
}
else
{
@@ -398,7 +445,7 @@ namespace JinEngine
/* print(string, x, y, lineheight, spacing) */
/* need set font */
- static int l_print(lua_State* L)
+ LUA_IMPLEMENT int l_print(lua_State* L)
{
Font* font = context.curFont;
if (font == nullptr)
@@ -410,15 +457,15 @@ namespace JinEngine
int y = luax_optnumber(L, 3, 0);
int lineheight = luax_optnumber(L, 4, font->getFontSize());
int spacing = luax_optnumber(L, 5, 0);
- font->print(text, x, y, lineheight, spacing);
+ font->render(text, x, y, lineheight, spacing);
return 0;
}
- static int l_setColor(lua_State* L)
+ LUA_IMPLEMENT int l_setColor(lua_State* L)
{
if (luax_gettop(L) == 0)
{
- glColor4f(1, 1, 1, 1);
+ gl.setColor(Color(255, 255, 255, 255));
return 0;
}
@@ -429,14 +476,11 @@ namespace JinEngine
context.curRenderColor.a = luax_checknumber(L, 4);
else
context.curRenderColor.a = 255;
- glColor4f(context.curRenderColor.r / 255.f,
- context.curRenderColor.g / 255.f,
- context.curRenderColor.b / 255.f,
- context.curRenderColor.a / 255.f);
+ gl.setColor(context.curRenderColor);
return 0;
}
- static int l_getColor(lua_State * L)
+ LUA_IMPLEMENT int l_getColor(lua_State * L)
{
luax_pushnumber(L, context.curRenderColor.r);
luax_pushnumber(L, context.curRenderColor.g);
@@ -445,7 +489,7 @@ namespace JinEngine
return 4;
}
- static int l_bindCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_bindCanvas(lua_State* L)
{
if (luax_gettop(L) == 0)
{
@@ -453,29 +497,29 @@ namespace JinEngine
Canvas::unbind();
return 0;
}
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- Ref<Canvas>& ref = proxy->getRef<Canvas>();
- Canvas::bind(ref.getObject());
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ Shared<Canvas>& shared = proxy->getShared<Canvas>();
+ Canvas::bind(shared.getObject());
return 0;
}
- static int l_unbindCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_unbindCanvas(lua_State* L)
{
Canvas::unbind();
return 0;
}
- static int l_useShader(lua_State* L)
+ LUA_IMPLEMENT int l_useShader(lua_State* L)
{
if (luax_gettop(L) == 0)
{
Shader::unuse();
return 0;
}
- if (luax_istype(L, 1, JIN_GRAPHICS_SHADER))
+ if (luax_istype(L, 1, Jin_Lua_Shader))
{
- Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Shader>& jsl = proxy->getRef<Shader>();
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Shader);
+ Shared<Shader>& jsl = proxy->getShared<Shader>();
jsl->use();
}
else
@@ -485,21 +529,13 @@ namespace JinEngine
return 0;
}
- static int l_setBlend(lua_State* L)
+ LUA_IMPLEMENT int l_setBlend(lua_State* L)
{
return 0;
}
- static RenderMode strtomode(const char* str)
- {
- std::string s = std::string(str);
- if (s == "fill") return RenderMode::FILL;
- else if (s == "line") return RenderMode::LINE;
- else return RenderMode::NONE;
- }
-
- static int l_point(lua_State* L)
+ LUA_IMPLEMENT int l_point(lua_State* L)
{
int x = luax_checknumber(L, 1);
int y = luax_checknumber(L, 2);
@@ -508,7 +544,7 @@ namespace JinEngine
return 0;
}
- static int l_line(lua_State* L)
+ LUA_IMPLEMENT int l_line(lua_State* L)
{
int x1 = luax_checknumber(L, 1);
int y1 = luax_checknumber(L, 2);
@@ -519,10 +555,9 @@ namespace JinEngine
return 0;
}
- static int l_rect(lua_State* L)
+ LUA_IMPLEMENT int l_rect(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -540,10 +575,9 @@ namespace JinEngine
return 0;
}
- static int l_circle(lua_State* L)
+ LUA_IMPLEMENT int l_circle(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -560,10 +594,9 @@ namespace JinEngine
return 0;
}
- static int l_triangle(lua_State* L)
+ LUA_IMPLEMENT int l_triangle(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -586,11 +619,10 @@ namespace JinEngine
return 0;
}
- static int l_polygon(lua_State* L)
+ LUA_IMPLEMENT int l_polygon(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
int n = luax_checknumber(L, 2);
- RenderMode mode = strtomode(modestr);
if (mode != RenderMode::NONE)
{
if (!luax_istable(L, 3))
@@ -601,7 +633,7 @@ namespace JinEngine
int tn = luax_tableidxlen(L, 3);
if (tn != n * 2)
{
- static char* emsg = \
+ LUA_IMPLEMENT char* emsg = \
"number of polygon vertices doesn't match " \
"provided n, expect %d numbers but get %d";
luax_error(L, emsg, n * 2, tn);
@@ -621,16 +653,16 @@ namespace JinEngine
return 0;
}
- static int l_newTTFData(lua_State* L)
+ LUA_IMPLEMENT int l_newTTFData(lua_State* L)
{
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TTFDATA, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_TTFData);
TTFData* fd = nullptr;
{
const char* path = luax_checkstring(L, 1);
AssetDatabase* fs = AssetDatabase::get();
if (!fs->exists(path))
{
- error(L, "No such font %s\n", path);
+ error(L, "No such font \"%s\"", path);
luax_pushnil(L);
return 1;
}
@@ -638,12 +670,12 @@ namespace JinEngine
fs->read(path, b);
fd = TTFData::createTTFData(&b, b.size());
}
- proxy->bind(new Ref<TTFData>(fd, JIN_GRAPHICS_TTFDATA));
+ proxy->bind(new Shared<TTFData>(fd, Jin_Lua_TTFData));
return 1;
}
-
+
/* newText(str[, encode]) */
- static int l_newText(lua_State* L)
+ LUA_IMPLEMENT int l_newText(lua_State* L)
{
Encode encode = Encode::UTF8;
if (luax_gettop(L) == 2)
@@ -661,20 +693,48 @@ namespace JinEngine
unsigned length;
const char* data = luax_checklstring(L, 1, &length);
Text* text = new Text(encode, data, length);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXT, sizeof(Proxy));
- proxy->bind(new Ref<Text>(text, JIN_GRAPHICS_TEXT));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Text);
+ proxy->bind(new Shared<Text>(text, Jin_Lua_Text));
return 1;
}
+ LUA_IMPLEMENT int l_newSprite(lua_State* L)
+ {
+ Proxy* p = luax_newinstance(L, Jin_Lua_Sprite);
+ p->bind(new Shared<Sprite>(new Sprite(), Jin_Lua_Sprite));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_newSpriteSheet(lua_State* L)
+ {
+ Proxy* pxyGraphic = nullptr;
+ if (luax_istype(L, 1, Jin_Lua_Texture))
+ pxyGraphic = (Proxy*)luax_checktype(L, 1, Jin_Lua_Texture);
+ else if(luax_istype(L, 1, Jin_Lua_Canvas))
+ pxyGraphic = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ if (pxyGraphic != nullptr)
+ {
+ Proxy* pxySSheet = luax_newinstance(L, Jin_Lua_SpriteSheet);
+ Graphic* graphic = pxyGraphic->getObject<Graphic>();
+ Shared<SpriteSheet>* shrSSheet = new Shared<SpriteSheet>(new SpriteSheet(graphic), Jin_Lua_SpriteSheet);
+ Shared<Graphic>& shrGraphic = pxyGraphic->getShared<Graphic>();
+ shrSSheet->setDependency((int)SpriteSheetDependency::DEP_GRAPHIC, &shrGraphic);
+ pxySSheet->bind(shrSSheet);
+ return 1;
+ }
+ else
+ return 0;
+ }
+
/* newTextureFont(bitmap, text, color | cellw, cellh) */
- static int l_newTextureFont(lua_State* L)
+ LUA_IMPLEMENT int l_newTextureFont(lua_State* L)
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Bitmap);
Bitmap* bitmap = p->getObject<Bitmap>();
Text* text;
- if (luax_istype(L, 2, JIN_GRAPHICS_TEXT))
+ if (luax_istype(L, 2, Jin_Lua_Text))
{
- Proxy* pt = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT);
+ Proxy* pt = (Proxy*)luax_checktype(L, 2, Jin_Lua_Text);
text = pt->getObject<Text>();
}
else if (luax_isstring(L, 2))
@@ -713,92 +773,78 @@ namespace JinEngine
// Delete temporary text.
delete text;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTUREFONT, sizeof(Proxy));
- proxy->bind(new Ref<TextureFont>(textureFont, JIN_GRAPHICS_TEXTUREFONT));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_TextureFont);
+ proxy->bind(new Shared<TextureFont>(textureFont, Jin_Lua_TextureFont));
return 1;
}
/* setFont(font) */
- static int l_setFont(lua_State* L)
+ LUA_IMPLEMENT int l_setFont(lua_State* L)
{
- if (luax_istype(L, 1, JIN_GRAPHICS_TTF))
+ if (luax_istype(L, 1, Jin_Lua_TTF))
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF);
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTF);
TTF* ttf = p->getObject<TTF>();
context.curFont = ttf;
}
- else if (luax_istype(L, 1, JIN_GRAPHICS_TEXTUREFONT))
+ else if (luax_istype(L, 1, Jin_Lua_TextureFont))
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT);
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_TextureFont);
TextureFont* tf = p->getObject<TextureFont>();
context.curFont = tf;
}
return 0;
}
- static int l_unsetFont(lua_State* L)
+ LUA_IMPLEMENT int l_unsetFont(lua_State* L)
{
context.curFont = context.defaultFont;
return 0;
}
- static const luaL_Reg f[] = {
- /* window */
- { "init", l_init },
- { "setTitle", l_setTitle },
- { "getSize", l_getSize },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "destroy", l_destroy },
- /* creators */
- { "newBitmap", l_newBitmap },
- { "newTexture", l_newTexture },
- { "newShader", l_newShader },
- { "newShaderf", l_newShaderf },
- { "newCanvas", l_newCanvas },
- { "newTTFData", l_newTTFData },
- { "newText", l_newText },
- { "newTextureFont", l_newTextureFont },
- /* render */
- { "setClearColor", l_setClearColor },
- { "clear", l_clear },
- { "draw", l_draw },
- { "print", l_print },
- { "drawq", l_drawq },
- { "setColor", l_setColor },
- { "getColor", l_getColor },
- { "present", l_present },
- /* canvas */
- { "bindCanvas", l_bindCanvas },
- { "unbindCanvas", l_unbindCanvas },
- /* shader */
- { "useShader", l_useShader },
- /* shapes */
- { "point", l_point },
- { "line", l_line },
- { "rect", l_rect },
- { "circle", l_circle },
- { "triangle", l_triangle },
- { "polygon", l_polygon },
- /* font */
- { "setFont", l_setFont },
- { "unsetFont", l_unsetFont },
- { 0, 0 }
- };
-
- extern int luaopen_Texture(lua_State* L);
- extern int luaopen_Text(lua_State* L);
- extern int luaopen_TTF(lua_State* L);
- extern int luaopen_TextureFont(lua_State* L);
- extern int luaopen_TTFData(lua_State* L);
- extern int luaopen_Page(lua_State* L);
- extern int luaopen_Canvas(lua_State* L);
- extern int luaopen_JSL(lua_State* L);
- extern int luaopen_Bitmap(lua_State* L);
-
- int luaopen_graphics(lua_State* L)
+ LUA_IMPLEMENT int l_clearMatrix(lua_State* L)
+ {
+ gl.clearMatrix();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pushMatrix(lua_State* L)
+ {
+ gl.push();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_popMatrix(lua_State* L)
+ {
+ gl.pop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_scale(lua_State* L)
+ {
+ float sx = luax_checknumber(L, 1);
+ float sy = luax_checknumber(L, 2);
+ gl.scale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_translate(lua_State* L)
+ {
+ float x = luax_checknumber(L, 1);
+ float y = luax_checknumber(L, 2);
+ gl.translate(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rotate(lua_State* L)
+ {
+ float r = luax_checknumber(L, 1);
+ gl.rotate(r);
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_graphics(lua_State* L)
{
- // register types
luaopen_Bitmap(L);
luaopen_Texture(L);
luaopen_Canvas(L);
@@ -807,13 +853,70 @@ namespace JinEngine
luaopen_Text(L);
luaopen_TextureFont(L);
luaopen_Page(L);
- luaopen_JSL(L);
-
- // load whole lib
+ luaopen_Shader(L);
+ luaopen_Sprite(L);
+ luaopen_SpriteSheet(L);
+
+ luaL_Reg f[] = {
+ /* window */
+ { "init", l_init },
+ { "setTitle", l_setTitle },
+ { "getSize", l_getSize },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "destroy", l_destroy },
+ { "hideWindow", l_hideWindow },
+ { "showWindow", l_showWindow },
+ /* creators */
+ { "newBitmap", l_newBitmap },
+ { "newTexture", l_newTexture },
+ { "newShader", l_newShader },
+ { "newShaderf", l_newShaderf },
+ { "newCanvas", l_newCanvas },
+ { "newTTFData", l_newTTFData },
+ { "newText", l_newText },
+ { "newTextureFont", l_newTextureFont },
+ { "newSprite", l_newSprite },
+ { "newSpriteSheet", l_newSpriteSheet },
+ /* render */
+ { "setClearColor", l_setClearColor },
+ { "clear", l_clear },
+ { "draw", l_draw },
+ { "print", l_print },
+ { "drawq", l_drawq },
+ { "setColor", l_setColor },
+ { "getColor", l_getColor },
+ { "present", l_present },
+ /* canvas */
+ { "bindCanvas", l_bindCanvas },
+ { "unbindCanvas", l_unbindCanvas },
+ /* shader */
+ { "useShader", l_useShader },
+ /* shapes */
+ { "point", l_point },
+ { "line", l_line },
+ { "rect", l_rect },
+ { "circle", l_circle },
+ { "triangle", l_triangle },
+ { "polygon", l_polygon },
+ /* font */
+ { "setFont", l_setFont },
+ { "unsetFont", l_unsetFont },
+ /* transform */
+ { "pushMatrix", l_pushMatrix },
+ { "clearMatrix", l_clearMatrix },
+ { "popMatrix", l_popMatrix },
+ { "translate", l_translate },
+ { "rotate", l_rotate },
+ { "scale", l_scale },
+ { 0, 0 }
+ };
+
+ // Load whole lib.
luax_newlib(L, f);
return 1;
}
- }// lua
-}// jin \ No newline at end of file
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_graphics.h b/src/lua/modules/graphics/je_lua_graphics.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_graphics.h
diff --git a/src/lua/modules/graphics/je_lua_page.cpp b/src/lua/modules/graphics/je_lua_page.cpp
new file mode 100644
index 0000000..20ec398
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_page.cpp
@@ -0,0 +1,69 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include <iostream>
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+using namespace JinEngine::Graphics::Shaders;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Page = "Page";
+
+ typedef Shared<Font>& SharedFont;
+
+ Page* getPage(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Page);
+ return proxy->getObject<Page>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Page);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ Page* page = getPage(L);
+ luax_pushinteger(L, page->size.w);
+ luax_pushinteger(L, page->size.h);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ Page* page = getPage(L);
+ luax_pushinteger(L, page->size.w);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
+ {
+ Page* page = getPage(L);
+ luax_pushinteger(L, page->size.h);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_Page(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getSize", l_getSize },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Page, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_page.h b/src/lua/modules/graphics/je_lua_page.h
new file mode 100644
index 0000000..e4a21a3
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_page.h
@@ -0,0 +1,22 @@
+#ifndef __JE_LUA_PAGE_H__
+#define __JE_LUA_PAGE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ enum class PageDependency
+ {
+ DEP_TTF = 1,
+ DEP_TEXTURE_FONT = 2,
+ };
+
+ extern const char* Jin_Lua_Page;
+
+ void luaopen_Page(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_particle_system.cpp b/src/lua/modules/graphics/je_lua_particle_system.cpp
new file mode 100644
index 0000000..7099a5c
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_particle_system.cpp
@@ -0,0 +1,11 @@
+#include "libjin/jin.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+
+
+ } // Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_particle_system.h b/src/lua/modules/graphics/je_lua_particle_system.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_particle_system.h
diff --git a/src/lua/modules/graphics/je_lua_shader.cpp b/src/lua/modules/graphics/je_lua_shader.cpp
new file mode 100644
index 0000000..1612a69
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_shader.cpp
@@ -0,0 +1,137 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_shader.h"
+#include "je_lua_canvas.h"
+#include "je_lua_texture.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Shaders;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Shader = "Shader";
+
+ typedef Shared<Shader>& ShaderRef;
+
+ static inline ShaderRef checkShader(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Shader);
+ return proxy->getShared<Shader>();
+ }
+
+ /**
+ * jsl:sendNumber("variable", 0.1)
+ */
+ LUA_IMPLEMENT int l_sendNumber(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ float number = luax_checknumber(L, 3);
+ shared->sendFloat(variable, number);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendTexture(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 3, Jin_Lua_Texture);
+ Shared<Texture>& tex = proxy->getShared<Texture>();
+ shared->sendTexture(variable, tex.getObject());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendCanvas(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 3, Jin_Lua_Canvas);
+ Shared<Canvas>& canvas = proxy->getShared<Canvas>();
+ shared->sendCanvas(variable, canvas.getObject());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendVec2(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ float x = luax_rawgetnumber(L, 3, 1);
+ float y = luax_rawgetnumber(L, 3, 2);
+ shared->sendVec2(variable, x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendVec3(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ float x = luax_rawgetnumber(L, 3, 1);
+ float y = luax_rawgetnumber(L, 3, 2);
+ float z = luax_rawgetnumber(L, 3, 3);
+ shared->sendVec3(variable, x, y, z);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendVec4(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ float x = luax_rawgetnumber(L, 3, 1);
+ float y = luax_rawgetnumber(L, 3, 2);
+ float z = luax_rawgetnumber(L, 3, 3);
+ float w = luax_rawgetnumber(L, 3, 4);
+ shared->sendVec4(variable, x, y, z, w);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendColor(lua_State* L)
+ {
+ return l_sendVec4(L);
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Shader);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Shader(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "sendNumber", l_sendNumber },
+ { "sendTexture", l_sendTexture },
+ { "sendCanvas", l_sendCanvas },
+ { "sendVec2", l_sendVec2 },
+ { "sendVec3", l_sendVec3 },
+ { "sendVec4", l_sendVec4 },
+ { "sendColor", l_sendColor },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Shader, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_shader.h b/src/lua/modules/graphics/je_lua_shader.h
new file mode 100644
index 0000000..5a84372
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_shader.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_SHDER_H__
+#define __JE_LUA_SHDER_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Shader;
+
+ void luaopen_Shader(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_sprite.cpp b/src/lua/modules/graphics/je_lua_sprite.cpp
new file mode 100644
index 0000000..97128a9
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_sprite.cpp
@@ -0,0 +1,262 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_sprite.h"
+#include "je_lua_canvas.h"
+#include "je_lua_texture.h"
+#include "je_lua_shader.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Shaders;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+ const char* Jin_Lua_Sprite = "Sprite";
+
+ typedef Shared<Sprite>& SharedSprite;
+
+ LUA_IMPLEMENT inline SharedSprite checkSprite(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ return proxy->getShared<Sprite>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ p->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setRotation(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float r = luax_checknumber(L, 2);
+ sprite->setRotation(r);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setOrigin(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ switch (luax_gettop(L))
+ {
+ case 2:
+ {
+ int origin = luax_checkinteger(L, 2);
+ sprite->setOrigin(static_cast<Sprite::Origin>(origin));
+ }
+ break;
+ case 3:
+ {
+ int x = luax_checkinteger(L, 2);
+ int y = luax_checkinteger(L, 3);
+ sprite->setOrigin(x, y);
+ }
+ break;
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setPosition(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ sprite->setPosition(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setScale(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float sx = luax_checknumber(L, 2);
+ float sy = luax_checknumber(L, 3);
+ sprite->setScale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setColor(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ Channel r = luax_checkinteger(L, 2);
+ Channel g = luax_checkinteger(L, 3);
+ Channel b = luax_checkinteger(L, 4);
+ Channel a = luax_checkinteger(L, 5);
+ sprite->setColor(Color(r, g, b, a));
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setShader(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 2, Jin_Lua_Shader);
+ Shader* shader = proxy->getObject<Shader>();
+ sprite->setShader(shader);
+ sprite.setDependency((int)SpriteDependency::DEP_SHADER, &proxy->getShared<Shader>());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setGraphic(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ Graphic* graphic = nullptr;
+ Proxy* p = nullptr;
+ if (luax_istype(L, 2, Jin_Lua_Texture))
+ p = (Proxy*)luax_checktype(L, 2, Jin_Lua_Texture);
+ else if (luax_istype(L, 2, Jin_Lua_Canvas))
+ p = (Proxy*)luax_checktype(L, 2, Jin_Lua_Canvas);
+ if (p != nullptr)
+ {
+ sprite->setGraphic(p->getObject<Graphic>());
+ sprite.setDependency((int)SpriteDependency::DEP_GRAPHIC, &p->getShared<Graphic>());
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_move(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ sprite->move(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_scale(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float sx = luax_checknumber(L, 2);
+ float sy = luax_checknumber(L, 3);
+ sprite->scale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rotate(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float r = luax_checknumber(L, 2);
+ sprite->rotate(r);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getRotation(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float r = sprite->getRotation();
+ luax_pushnumber(L, r);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getPosition(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Math::Vector2<float>& pos = sprite->getPosition();
+ luax_pushnumber(L, pos.x);
+ luax_pushnumber(L, pos.y);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getOrigin(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Math::Vector2<int>& origin = sprite->getOrigin();
+ luax_pushinteger(L, origin.x);
+ luax_pushinteger(L, origin.y);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getScale(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Math::Vector2<float> scale = sprite->getScale();
+ luax_pushnumber(L, scale.x);
+ luax_pushnumber(L, scale.y);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getColor(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Color& c = sprite->getColor();
+ luax_pushinteger(L, c.r);
+ luax_pushinteger(L, c.g);
+ luax_pushinteger(L, c.b);
+ luax_pushinteger(L, c.a);
+ return 4;
+ }
+
+ LUA_IMPLEMENT int l_render(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ sprite->render();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getGraphic(lua_State* L)
+ {
+ Proxy* pxySprite = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ Shared<Sprite>& shrSprite = pxySprite->getShared<Sprite>();
+ SharedBase* shrGraphic = shrSprite.getDependency((int)SpriteDependency::DEP_GRAPHIC);
+ if (shrGraphic->isType(Jin_Lua_Canvas))
+ {
+ Proxy* pxyCanvas = luax_newinstance(L, Jin_Lua_Canvas);
+ pxyCanvas->bind(shrGraphic);
+ return 1;
+ }
+ else if (shrGraphic->isType(Jin_Lua_Texture))
+ {
+ Proxy* pxyTexture = luax_newinstance(L, Jin_Lua_Texture);
+ pxyTexture->bind(shrGraphic);
+ return 1;
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getShader(lua_State* L)
+ {
+ Proxy* pxySprite = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ Shared<Sprite>& shrSprite = pxySprite->getShared<Sprite>();
+ SharedBase* shrShader = shrSprite.getDependency((int)SpriteDependency::DEP_SHADER);
+ if (shrShader != nullptr && shrShader->isType(Jin_Lua_Shader))
+ {
+ Proxy* pxyShader = luax_newinstance(L, Jin_Lua_Shader);
+ pxyShader->bind(shrShader);
+ return 1;
+ }
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Sprite(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "render", l_render },
+ { "setRotation", l_setRotation },
+ { "setOrigin", l_setOrigin },
+ { "setPosition", l_setPosition },
+ { "setScale", l_setScale },
+ { "setColor", l_setColor },
+ { "setShader", l_setShader },
+ { "setGraphic", l_setGraphic },
+ { "move", l_move },
+ { "scale", l_scale },
+ { "rotate", l_rotate },
+ { "getRotation", l_getRotation },
+ { "getPosition", l_getPosition },
+ { "getOrigin", l_getOrigin },
+ { "getScale", l_getScale },
+ { "getColor", l_getColor },
+ { "getShader", l_getShader },
+ { "getGraphic", l_getGraphic },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Sprite, methods);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_sprite.h b/src/lua/modules/graphics/je_lua_sprite.h
new file mode 100644
index 0000000..02c44bf
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_sprite.h
@@ -0,0 +1,24 @@
+#ifndef __JE_LUA_SPRITE_H__
+#define __JE_LUA_SPRITE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ // Sprite dependency slots.
+ enum class SpriteDependency
+ {
+ DEP_GRAPHIC = 1,
+ DEP_SHADER = 2,
+ DEP_SPRITESHEET = 3
+ };
+
+ extern const char* Jin_Lua_Sprite;
+
+ void luaopen_Sprite(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_spritesheet.cpp b/src/lua/modules/graphics/je_lua_spritesheet.cpp
new file mode 100644
index 0000000..15469e9
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_spritesheet.cpp
@@ -0,0 +1,54 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_sprite.h"
+#include "je_lua_spritesheet.h"
+
+using namespace JinEngine::Math;
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_SpriteSheet = "SpriteSheet";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* pxySSheet = (Proxy*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
+ pxySSheet->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newSprite(lua_State* L)
+ {
+ Proxy* pxySSheet = (Proxy*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
+ Shared<SpriteSheet>& shrSSheet = pxySSheet->getShared<SpriteSheet>();
+ SpriteSheet* sheet = pxySSheet->getObject<SpriteSheet>();
+ Quad quad;
+ quad.x = luax_checkinteger(L, 2);
+ quad.y = luax_checkinteger(L, 3);
+ quad.w = luax_checkinteger(L, 4);
+ quad.h = luax_checkinteger(L, 5);
+ Sprite* spr = sheet->createSprite(quad);
+ Proxy* pxySprite = luax_newinstance(L, Jin_Lua_Sprite);
+ Shared<Sprite>* shrSprite = new Shared<Sprite>(spr, Jin_Lua_Sprite);
+ shrSprite->setDependency((int)SpriteDependency::DEP_SPRITESHEET, &shrSSheet);
+ pxySprite->bind(shrSprite);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_SpriteSheet(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "newSprite", l_newSprite },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_SpriteSheet, methods);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_spritesheet.h b/src/lua/modules/graphics/je_lua_spritesheet.h
new file mode 100644
index 0000000..bcae60b
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_spritesheet.h
@@ -0,0 +1,21 @@
+#ifndef __JE_LUA_SPRITE_SHEET_H__
+#define __JE_LUA_SPRITE_SHEET_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ enum class SpriteSheetDependency
+ {
+ DEP_GRAPHIC = 1
+ };
+
+ extern const char* Jin_Lua_SpriteSheet;
+
+ void luaopen_SpriteSheet(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_text.cpp b/src/lua/modules/graphics/je_lua_text.cpp
new file mode 100644
index 0000000..9377a0a
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_text.cpp
@@ -0,0 +1,32 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Text = "Text";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Text);
+ p->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Text(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Text, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_text.h b/src/lua/modules/graphics/je_lua_text.h
new file mode 100644
index 0000000..dfcc9cc
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_text.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TEXT_H__
+#define __JE_LUA_TEXT_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Text;
+
+ void luaopen_Text(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture.cpp b/src/lua/modules/graphics/je_lua_texture.cpp
new file mode 100644
index 0000000..79ddc63
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_texture.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Texture = "Texture";
+
+ typedef Shared<Texture>& SharedTexture;
+
+ LUA_IMPLEMENT inline SharedTexture checkTexture(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Texture);
+ return proxy->getShared<Texture>();
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getWidth());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State *L)
+ {
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getHeight());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getWidth());
+ luax_pushnumber(L, shared->getHeight());
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Texture);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Texture(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Texture, f);
+ }
+
+ }// namespace Lua
+}// namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture.h b/src/lua/modules/graphics/je_lua_texture.h
new file mode 100644
index 0000000..c8bb71c
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TEXTURE_H__
+#define __JE_LUA_TEXTURE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Texture;
+
+ void luaopen_Texture(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp
new file mode 100644
index 0000000..8ca3ce5
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture_font.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_page.h"
+#include "je_lua_text.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TextureFont = "TextureFont";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_TextureFont);
+ proxy->release();
+ return 0;
+ }
+
+ /* typeset(Text | string, lineheight, spacing) */
+ LUA_IMPLEMENT int l_typeset(lua_State* L)
+ {
+ Proxy* pxyTexFont = (Proxy*)luax_checktype(L, 1, Jin_Lua_TextureFont);
+ Shared<TextureFont>& shrTexFont = pxyTexFont->getShared<TextureFont>();
+ TextureFont* tf = pxyTexFont->getObject<TextureFont>();
+ int lineheight = luax_checkinteger(L, 3);
+ int spacing = luax_optnumber(L, 4, 0);
+ Page* page = nullptr;
+ if (luax_isstring(L, 2))
+ {
+ unsigned length;
+ const char* str = luax_checklstring(L, 2, &length);
+ Text text(Encode::UTF8, str, length);
+ page = tf->typeset(text, lineheight, spacing);
+ }
+ else if (luax_istype(L, 2, Jin_Lua_Text))
+ {
+ Proxy* p2 = (Proxy*)luax_checktype(L, 2, Jin_Lua_Text);
+ Text* text = p2->getObject<Text>();
+ page = tf->typeset(*text, lineheight, spacing);
+ }
+ Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page);
+ Shared<Page>* shrPage = new Shared<Page>(page, Jin_Lua_Page);
+ shrPage->setDependency((int)PageDependency::DEP_TEXTURE_FONT, &shrTexFont);
+ pxyPage->bind(shrPage);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_TextureFont(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TextureFont, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture_font.h b/src/lua/modules/graphics/je_lua_texture_font.h
new file mode 100644
index 0000000..d1fffe5
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture_font.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TEXTURE_FONT_H__
+#define __JE_LUA_TEXTURE_FONT_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_TextureFont;
+
+ void luaopen_TextureFont(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp
new file mode 100644
index 0000000..c5d922b
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_page.h"
+#include "je_lua_text.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TTF = "TTF";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTF);
+ proxy->release();
+ return 0;
+ }
+
+ /* typeset(Text | string, lineheight, spacing) */
+ LUA_IMPLEMENT int l_typeset(lua_State* L)
+ {
+ Proxy* pxyTTF = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTF);
+ Shared<TTF>& shrTTF = pxyTTF->getShared<TTF>();
+ TTF* ttf = pxyTTF->getObject<TTF>();
+ int lineheight = luax_optnumber(L, 3, ttf->getFontSize());
+ int spacing = luax_optnumber(L, 4, 0);
+ Page* page = nullptr;
+ if (luax_isstring(L, 2))
+ {
+ unsigned length;
+ const char* str = luax_checklstring(L, 2, &length);
+ Text text(Encode::UTF8, str, length);
+ page = ttf->typeset(text, lineheight, spacing);
+ }
+ else if (luax_istype(L, 2, Jin_Lua_Text))
+ {
+ Proxy* pxyText = (Proxy*)luax_checktype(L, 2, Jin_Lua_Text);
+ Text* text = pxyText->getObject<Text>();
+ page = ttf->typeset(*text, lineheight, spacing);
+ }
+ Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page);
+ Shared<Page>* refPage = new Shared<Page>(page, Jin_Lua_Page);
+ refPage->setDependency((int)PageDependency::DEP_TTF, &shrTTF);
+ pxyPage->bind(refPage);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_TTF(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TTF, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf.h b/src/lua/modules/graphics/je_lua_ttf.h
new file mode 100644
index 0000000..bfe503d
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TTF_H__
+#define __JE_LUA_TTF_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_TTF;
+
+ void luaopen_TTF(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf_data.cpp b/src/lua/modules/graphics/je_lua_ttf_data.cpp
new file mode 100644
index 0000000..1277318
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf_data.cpp
@@ -0,0 +1,52 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_ttf.h"
+#include "je_lua_ttf_data.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TTFData = "TTFData";
+
+ LUA_IMPLEMENT int l_newTTF(lua_State* L)
+ {
+ Proxy* pxyTTFData = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTFData);
+ int fontsize = luax_checkinteger(L, 2);
+ Shared<TTFData>& shrFontData = pxyTTFData->getShared<TTFData>();
+ TTFData* fontData = shrFontData.getObject();
+ Proxy* pxyTTF = luax_newinstance(L, Jin_Lua_TTF);
+ TTF* font = fontData->createTTF(fontsize);
+ Shared<TTF>* shrTTF = new Shared<TTF>(font, Jin_Lua_TTF);
+ shrTTF->setDependency((int)TTFDependency::DEP_TTFDATA, &shrFontData);
+ pxyTTF->bind(shrTTF);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTFData);
+ p->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_TTFData(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "newTTF", l_newTTF },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TTFData, f);
+
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf_data.h b/src/lua/modules/graphics/je_lua_ttf_data.h
new file mode 100644
index 0000000..1fd832d
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf_data.h
@@ -0,0 +1,21 @@
+#ifndef __JE_LUA_TTFDATA_H__
+#define __JE_LUA_TTFDATA_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ enum class TTFDependency
+ {
+ DEP_TTFDATA = 1,
+ };
+
+ extern const char* Jin_Lua_TTFData;
+
+ void luaopen_TTFData(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/page.cpp b/src/lua/modules/graphics/page.cpp
deleted file mode 100644
index 8c9e918..0000000
--- a/src/lua/modules/graphics/page.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-#include <iostream>
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Font>& FontRef;
-
- Page* getPage(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_PAGE);
- return proxy->getObject<Page>();
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_PAGE);
- {
- /* release font */
- Ref<Page>* page = &proxy->getRef<Page>();
- RefBase* font = (RefBase*)page->getUserdata();
- font->release();
- }
- proxy->release();
- return 0;
- }
-
- static int l_getSize(lua_State* L)
- {
- Page* page = getPage(L);
- luax_pushinteger(L, page->size.w);
- luax_pushinteger(L, page->size.h);
- return 2;
- }
-
- static int l_getWidth(lua_State* L)
- {
- Page* page = getPage(L);
- luax_pushinteger(L, page->size.w);
- return 1;
- }
-
- static int l_getHeight(lua_State* L)
- {
- Page* page = getPage(L);
- luax_pushinteger(L, page->size.h);
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getSize", l_getSize },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { 0, 0 }
- };
-
- int luaopen_Page(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_PAGE, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/shader.cpp b/src/lua/modules/graphics/shader.cpp
deleted file mode 100644
index d7733d4..0000000
--- a/src/lua/modules/graphics/shader.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Shader>& ShaderRef;
-
- static inline ShaderRef checkShader(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER);
- return proxy->getRef<Shader>();
- }
-
- /**
- * jsl:sendNumber("variable", 0.1)
- */
- static int l_sendNumber (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- float number = luax_checknumber(L, 3);
- ref->sendFloat(variable, number);
- return 0;
- }
-
- static int l_sendTexture (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_TEXTURE);
- Ref<Texture>& tex = proxy->getRef<Texture>();
- ref->sendTexture(variable, tex.getObject());
- return 0;
- }
-
- static int l_sendCanvas (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_CANVAS);
- Ref<Canvas>& canvas = proxy->getRef<Canvas>();
- ref->sendCanvas(variable, canvas.getObject());
- return 0;
- }
-
- static int l_sendVec2 (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- if (!luax_istable(L, 3))
- {
- luax_typerror(L, 3, "table");
- return 1;
- }
- float x = luax_rawgetnumber(L, 3, 1);
- float y = luax_rawgetnumber(L, 3, 2);
- ref->sendVec2(variable, x, y);
- return 0;
- }
-
- static int l_sendVec3 (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- if (!luax_istable(L, 3))
- {
- luax_typerror(L, 3, "table");
- return 1;
- }
- float x = luax_rawgetnumber(L, 3, 1);
- float y = luax_rawgetnumber(L, 3, 2);
- float z = luax_rawgetnumber(L, 3, 3);
- ref->sendVec3(variable, x, y, z);
- return 0;
- }
-
- static int l_sendVec4 (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- if (!luax_istable(L, 3))
- {
- luax_typerror(L, 3, "table");
- return 1;
- }
- float x = luax_rawgetnumber(L, 3, 1);
- float y = luax_rawgetnumber(L, 3, 2);
- float z = luax_rawgetnumber(L, 3, 3);
- float w = luax_rawgetnumber(L, 3, 4);
- ref->sendVec4(variable, x, y, z, w);
- return 0;
- }
-
- static int l_sendColor (lua_State* L)
- {
- return l_sendVec4(L);
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "sendNumber", l_sendNumber },
- { "sendTexture", l_sendTexture },
- { "sendCanvas", l_sendCanvas },
- { "sendVec2", l_sendVec2 },
- { "sendVec3", l_sendVec3 },
- { "sendVec4", l_sendVec4 },
- { "sendColor", l_sendColor },
- { 0, 0 }
- };
-
- /**
- * JSL program
- */
- int luaopen_JSL(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_SHADER, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/text.cpp b/src/lua/modules/graphics/text.cpp
deleted file mode 100644
index cbc82f1..0000000
--- a/src/lua/modules/graphics/text.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_gc(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXT);
- p->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { 0, 0 }
- };
-
- int luaopen_Text(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TEXT, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/texture.cpp b/src/lua/modules/graphics/texture.cpp
deleted file mode 100644
index 61bfaee..0000000
--- a/src/lua/modules/graphics/texture.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Texture>& TextureRef;
-
- static inline TextureRef checkTexture(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTURE);
- return proxy->getRef<Texture>();
- }
-
- static int l_getWidth(lua_State* L)
- {
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getWidth());
- return 1;
- }
-
- static int l_getHeight(lua_State *L)
- {
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getHeight());
- return 1;
- }
-
- static int l_getSize(lua_State* L)
- {
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getWidth());
- luax_pushnumber(L, ref->getHeight());
- return 2;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTURE);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { 0, 0 }
- };
-
- int luaopen_Texture(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TEXTURE, f);
- return 0;
- }
-
- }// lua
-}// jin \ No newline at end of file
diff --git a/src/lua/modules/graphics/texture_font.cpp b/src/lua/modules/graphics/texture_font.cpp
deleted file mode 100644
index a2e88ba..0000000
--- a/src/lua/modules/graphics/texture_font.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT);
- proxy->release();
- return 0;
- }
-
- /* typeset(Text | string, lineheight, spacing) */
- static int l_typeset(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT);
- TextureFont* tf = p->getObject<TextureFont>();
- int lineheight = luax_checkinteger(L, 3);
- int spacing = luax_optnumber(L, 4, 0);
- Page* page = nullptr;
- if (luax_isstring(L, 2))
- {
- unsigned length;
- const char* str = luax_checklstring(L, 2, &length);
- Text text(Encode::UTF8, str, length);
- page = tf->typeset(text, lineheight, spacing);
- }
- else if (luax_istype(L, 2, JIN_GRAPHICS_TEXT))
- {
- Proxy* p2 = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT);
- Text* text = p2->getObject<Text>();
- page = tf->typeset(*text, lineheight, spacing);
- }
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy));
- Ref<Page>* refPage = new Ref<Page>(page, JIN_GRAPHICS_PAGE);
- {
- /* retain related ttf */
- Ref<TextureFont>& refTF = p->getRef<TextureFont>();
- refTF.retain();
- refPage->setUserdata(&refTF);
- }
- proxy->bind(refPage);
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "typeset", l_typeset },
- { 0, 0 }
- };
-
- int luaopen_TextureFont(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TEXTUREFONT, f);
-
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/ttf.cpp b/src/lua/modules/graphics/ttf.cpp
deleted file mode 100644
index 414c7eb..0000000
--- a/src/lua/modules/graphics/ttf.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF);
- {
- /* release ttf data */
- Ref<TTF>* ttf = &proxy->getRef<TTF>();
- RefBase* data = (RefBase*)ttf->getUserdata();
- data->release();
- }
- proxy->release();
- return 0;
- }
-
- /* typeset(Text | string, lineheight, spacing) */
- static int l_typeset(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF);
- TTF* ttf = p->getObject<TTF>();
- int lineheight = luax_optnumber(L, 3, ttf->getFontSize());
- int spacing = luax_optnumber(L, 4, 0);
- Page* page = nullptr;
- if (luax_isstring(L, 2))
- {
- unsigned length;
- const char* str = luax_checklstring(L, 2, &length);
- Text text(Encode::UTF8, str, length);
- page = ttf->typeset(text, lineheight, spacing);
- }
- else if (luax_istype(L, 2, JIN_GRAPHICS_TEXT))
- {
- Proxy* p2 = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT);
- Text* text = p2->getObject<Text>();
- page = ttf->typeset(*text, lineheight, spacing);
- }
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy));
- Ref<Page>* refPage = new Ref<Page>(page, JIN_GRAPHICS_PAGE);
- {
- /* retain related ttf */
- Ref<TTF>& refTTF = p->getRef<TTF>();
- refTTF.retain();
- refPage->setUserdata(&refTTF);
- }
- proxy->bind(refPage);
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "typeset", l_typeset },
- { 0, 0 }
- };
-
- int luaopen_TTF(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TTF, f);
-
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/ttfData.cpp b/src/lua/modules/graphics/ttfData.cpp
deleted file mode 100644
index 43c3613..0000000
--- a/src/lua/modules/graphics/ttfData.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_newTTF(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTFDATA);
- int fontsize = luax_checkinteger(L, 2);
- Ref<TTFData>& refFontData = p->getRef<TTFData>();
- TTFData* fontData = refFontData.getObject();
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TTF, sizeof(Proxy));
- TTF* font = fontData->createTTF(fontsize);
- Ref<TTF>* refTTF = new Ref<TTF>(font, JIN_GRAPHICS_TTF);
- {
- Ref<TTFData>& refTTFData = p->getRef<TTFData>();
- refTTFData.retain();
- refTTF->setUserdata(&refTTFData);
- }
- proxy->bind(refTTF);
- return 1;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTFDATA);
- p->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "newTTF", l_newTTF },
- { 0, 0 }
- };
-
- int luaopen_TTFData(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TTFDATA, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/joypad/joypad.cpp b/src/lua/modules/joypad/je_lua_joypad.cpp
index d67a624..a57fc99 100644
--- a/src/lua/modules/joypad/joypad.cpp
+++ b/src/lua/modules/joypad/je_lua_joypad.cpp
@@ -1,17 +1,17 @@
-#include "libjin/jin.h"
#include "lua/modules/luax.h"
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
namespace JinEngine
{
namespace Lua
{
- static const luaL_Reg f[] = {
- { 0, 0 }
- };
-
- int luaopen_joypad(lua_State* L)
+ LUA_EXPORT int luaopen_joypad(lua_State* L)
{
+ luaL_Reg f[] = {
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/joypad/je_lua_joypad.h b/src/lua/modules/joypad/je_lua_joypad.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/joypad/je_lua_joypad.h
diff --git a/src/lua/modules/keyboard/keyboard.cpp b/src/lua/modules/keyboard/je_lua_keyboard.cpp
index 727a51e..6b7f3cd 100644
--- a/src/lua/modules/keyboard/keyboard.cpp
+++ b/src/lua/modules/keyboard/je_lua_keyboard.cpp
@@ -1,3 +1,4 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
namespace JinEngine
@@ -6,7 +7,7 @@ namespace JinEngine
{
//https://wiki.libsdl.org/SDL_Keycode
- int luaopen_keyboard(lua_State* L)
+ LUA_EXPORT int luaopen_keyboard(lua_State* L)
{
luax_newlib(L, 0);
return 1;
diff --git a/src/lua/modules/keyboard/je_lua_keyboard.h b/src/lua/modules/keyboard/je_lua_keyboard.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/keyboard/je_lua_keyboard.h
diff --git a/src/lua/modules/math/math.cpp b/src/lua/modules/math/je_lua_math.cpp
index 4891762..2afeaf9 100644
--- a/src/lua/modules/math/math.cpp
+++ b/src/lua/modules/math/je_lua_math.cpp
@@ -1,3 +1,4 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
@@ -6,7 +7,7 @@ namespace JinEngine
namespace Lua
{
- static int l_mod(lua_State* L)
+ LUA_IMPLEMENT int l_mod(lua_State* L)
{
int n = luax_checkinteger(L, 1);
int m = luax_checkinteger(L, 2);
@@ -15,13 +16,12 @@ namespace JinEngine
return 1;
}
- static const luaL_Reg f[] = {
- { "mod", l_mod },
- { 0, 0 }
- };
-
- int luaopen_math(lua_State* L)
+ LUA_EXPORT int luaopen_math(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "mod", l_mod },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
}
diff --git a/src/lua/modules/math/je_lua_math.h b/src/lua/modules/math/je_lua_math.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/math/je_lua_math.h
diff --git a/src/lua/modules/mouse/mouse.cpp b/src/lua/modules/mouse/je_lua_mouse.cpp
index 9d45178..9e6824a 100644
--- a/src/lua/modules/mouse/mouse.cpp
+++ b/src/lua/modules/mouse/je_lua_mouse.cpp
@@ -1,14 +1,15 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
+using namespace JinEngine::Input;
+
namespace JinEngine
{
namespace Lua
{
- using namespace JinEngine::Input;
-
- static int l_pos(lua_State* L)
+ LUA_IMPLEMENT int l_pos(lua_State* L)
{
static Mouse* mouse = Mouse::get();
int x, y;
@@ -18,22 +19,21 @@ namespace JinEngine
return 2;
}
- static int l_setVisible(lua_State* L)
+ LUA_IMPLEMENT int l_setVisible(lua_State* L)
{
bool visible = luax_checkbool(L, 1);
Mouse* mouse = Mouse::get();
mouse->setVisible(visible);
return 0;
}
-
- static const luaL_Reg f[] = {
- { "position", l_pos },
- { "setVisible", l_setVisible },
- { 0, 0 }
- };
- int luaopen_mouse(lua_State* L)
+ LUA_EXPORT int luaopen_mouse(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "getPosition", l_pos },
+ { "setVisible", l_setVisible },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
}
diff --git a/src/lua/modules/mouse/je_lua_mouse.h b/src/lua/modules/mouse/je_lua_mouse.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/mouse/je_lua_mouse.h
diff --git a/src/lua/modules/net/Buffer.cpp b/src/lua/modules/net/Buffer.cpp
deleted file mode 100644
index ddfbd6b..0000000
--- a/src/lua/modules/net/Buffer.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-#include "Buffer.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
- namespace Net
- {
-
- using namespace JinEngine;
-
- typedef Ref<Buffer>& BufferRef;
-
- static inline BufferRef checkNetBuffer(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER);
- return proxy->getRef<Buffer>();
- }
-
- // net.Buffer:append(value) -> value_length
- static int l_append(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- const int vp = 2;
- if (luax_isintegerstrict(L, vp))
- {
- int n = luax_checkinteger(L, vp);
- int size = sizeof(n);
- ref->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isfloatstrict(L, vp))
- {
- float n = luax_checknumber(L, vp);
- int size = sizeof(n);
- ref->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isbooleanstrict(L, vp))
- {
- bool n = luax_checkbool(L, vp);
- int size = sizeof(n);
- ref->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isstringstrict(L, vp))
- {
- const char* str = luax_checkstring(L, vp);
- int size = strlen(str) + 1;
- ref->append(str, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else
- {
- luax_typerror(L, vp, "number, bool or string");
- return 0;
- }
- }
-
- // net.Buffer:grabString(offset) -> string, length
- static int l_grabString(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- unsigned int len;
- char* data = ref->grabString(&len, offset);
- Array<char> str;
- str.bind(data, len);
- luax_pushstring(L, &str);
- luax_pushinteger(L, str.count());
- return 2;
- }
-
- // net.Buffer:grabInteger(offset) -> integer, length
- static int l_grabInteger(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- int integer = ref->grabInteger(&len, offset);
- luax_pushinteger(L, integer);
- luax_pushinteger(L, len);
- return 2;
- }
-
- static int l_grabFloat(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- float floatv = ref->grabFloat(&len, offset);
- luax_pushnumber(L, floatv);
- luax_pushinteger(L, len);
- return 2;
- }
-
- static int l_grabBoolean(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- bool boolean = ref->grabBoolean(&len, offset);
- luax_pushboolean(L, boolean);
- luax_pushinteger(L, len);
- return 2;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg netbuffer_function[] = {
- { "__gc", l_gc },
- { "append", l_append },
- { "grabString", l_grabString },
- { "grabInteger", l_grabInteger },
- { "grabBoolean", l_grabBoolean },
- { "grabFloat", l_grabFloat },
- { 0, 0 }
- };
-
- } // namespace Net
-
- int luaopen_Buffer(lua_State* L)
- {
- luax_newtype(L, JIN_NETWORK_BUFFER, Net::netbuffer_function);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/net/je_lua_buffer.cpp b/src/lua/modules/net/je_lua_buffer.cpp
new file mode 100644
index 0000000..0198095
--- /dev/null
+++ b/src/lua/modules/net/je_lua_buffer.cpp
@@ -0,0 +1,137 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_buffer.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Buffer = "Buffer";
+
+ typedef Shared<Net::Buffer>& SharedBuffer;
+
+ static inline SharedBuffer checkNetBuffer(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Buffer);
+ return proxy->getShared<Net::Buffer>();
+ }
+
+ // net.Buffer:append(value) -> value_length
+ LUA_IMPLEMENT int l_append(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ const int vp = 2;
+ if (luax_isintegerstrict(L, vp))
+ {
+ int n = luax_checkinteger(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else if (luax_isfloatstrict(L, vp))
+ {
+ float n = luax_checknumber(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else if (luax_isbooleanstrict(L, vp))
+ {
+ bool n = luax_checkbool(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else if (luax_isstringstrict(L, vp))
+ {
+ const char* str = luax_checkstring(L, vp);
+ int size = strlen(str) + 1;
+ shared->append(str, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else
+ {
+ luax_typerror(L, vp, "number, bool or string");
+ return 0;
+ }
+ }
+
+ // net.Buffer:grabString(offset) -> string, length
+ LUA_IMPLEMENT int l_grabString(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ unsigned int len;
+ char* data = shared->grabString(&len, offset);
+ Array<char> str;
+ str.bind(data, len);
+ luax_pushstring(L, &str);
+ luax_pushinteger(L, str.count());
+ return 2;
+ }
+
+ // net.Buffer:grabInteger(offset) -> integer, length
+ LUA_IMPLEMENT int l_grabInteger(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ int integer = shared->grabInteger(&len, offset);
+ luax_pushinteger(L, integer);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_grabFloat(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ float floatv = shared->grabFloat(&len, offset);
+ luax_pushnumber(L, floatv);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_grabBoolean(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ bool boolean = shared->grabBoolean(&len, offset);
+ luax_pushboolean(L, boolean);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Buffer);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Buffer(lua_State* L)
+ {
+ luaL_Reg netbuffer_function[] = {
+ { "__gc", l_gc },
+ { "append", l_append },
+ { "grabString", l_grabString },
+ { "grabInteger", l_grabInteger },
+ { "grabBoolean", l_grabBoolean },
+ { "grabFloat", l_grabFloat },
+ { 0, 0 }
+ };
+
+ luax_newtype(L, Jin_Lua_Buffer, netbuffer_function);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/net/Buffer.h b/src/lua/modules/net/je_lua_buffer.h
index 8733778..d226640 100644
--- a/src/lua/modules/net/Buffer.h
+++ b/src/lua/modules/net/je_lua_buffer.h
@@ -3,12 +3,17 @@
#include <cstring>
#include <cstdlib>
-#include "lua/common/common.h"
+#include "lua/common/je_lua_common.h"
namespace JinEngine
{
namespace Lua
{
+
+ extern const char* Jin_Lua_Buffer;
+
+ void luaopen_Buffer(lua_State* L);
+
namespace Net
{
diff --git a/src/lua/modules/net/net.cpp b/src/lua/modules/net/je_lua_net.cpp
index 4ef9ece..b081733 100644
--- a/src/lua/modules/net/net.cpp
+++ b/src/lua/modules/net/je_lua_net.cpp
@@ -1,8 +1,10 @@
#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
+
#include "libjin/jin.h"
-#include "lua/common/common.h"
-#include "Buffer.h"
+#include "lua/common/je_lua_common.h"
+
+#include "je_lua_buffer.h"
+#include "je_lua_socket.h"
namespace JinEngine
{
@@ -12,13 +14,13 @@ namespace Lua
using namespace JinEngine::Lua::Net;
using namespace JinEngine::Net;
- static int l_initNetwork(lua_State* L)
+ LUA_IMPLEMENT int l_initNetwork(lua_State* L)
{
JinEngine::Net::NetManager::get()->init();
return 1;
}
- static int l_Socket(lua_State* L)
+ LUA_IMPLEMENT int l_Socket(lua_State* L)
{
SocketInformation info = { 0 };
{
@@ -48,35 +50,31 @@ namespace Lua
}
}
Socket* socket = new Socket(info);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy));
- proxy->bind(new Ref<Socket>(socket, JIN_NETWORK_SOCKET));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket);
+ proxy->bind(new Shared<Socket>(socket, Jin_Lua_Socket));
return 1;
}
- static int l_Buffer(lua_State* L)
+ LUA_IMPLEMENT int l_Buffer(lua_State* L)
{
int size = luax_checkinteger(L, 1);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer);
Net::Buffer* buffer = new Net::Buffer(size);
- proxy->bind(new Ref<Buffer>(buffer, JIN_NETWORK_BUFFER));
+ proxy->bind(new Shared<Buffer>(buffer, Jin_Lua_Buffer));
return 1;
}
- static const luaL_Reg f[] = {
- { "init", l_initNetwork },
- { "newSocket", l_Socket },
- { "newBuffer", l_Buffer },
- { 0, 0 }
- };
-
- extern int luaopen_Socket(lua_State* L);
- extern int luaopen_Buffer(lua_State* L);
-
- int luaopen_net(lua_State* L)
+ LUA_EXPORT int luaopen_net(lua_State* L)
{
luaopen_Socket(L);
luaopen_Buffer(L);
-
+
+ luaL_Reg f[] = {
+ { "init", l_initNetwork },
+ { "newSocket", l_Socket },
+ { "newBuffer", l_Buffer },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/net/je_lua_net.h b/src/lua/modules/net/je_lua_net.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/net/je_lua_net.h
diff --git a/src/lua/modules/net/je_lua_socket.cpp b/src/lua/modules/net/je_lua_socket.cpp
new file mode 100644
index 0000000..db170e4
--- /dev/null
+++ b/src/lua/modules/net/je_lua_socket.cpp
@@ -0,0 +1,129 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_buffer.h"
+
+using namespace JinEngine::Net;
+using namespace JinEngine::Lua::Net;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Socket = "Socket";
+
+ typedef Shared<Socket>& SharedSocket;
+
+ const int BUFFER_SIZE = 1024;
+
+ LUA_IMPLEMENT inline SharedSocket checkSocket(lua_State* L, int pos = 1)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, pos, Jin_Lua_Socket);
+ return proxy->getShared<Socket>();
+ }
+
+ LUA_IMPLEMENT inline Shared<Buffer>& checkNetBuffer(lua_State* L, int pos = 1)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, pos, Jin_Lua_Buffer);
+ return proxy->getShared<Buffer>();
+ }
+
+ // return net.Socket
+ LUA_IMPLEMENT int l_accept(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ Socket* client = socket->accept();
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket);
+ proxy->bind(new Shared<Socket>(client, Jin_Lua_Socket));
+ return 1;
+ }
+
+ // return net.Buffer
+ LUA_IMPLEMENT int l_receive(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ char buffer[BUFFER_SIZE] = {0};
+ int size = socket->receive(buffer, BUFFER_SIZE);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer);
+ Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
+ proxy->bind(new Shared<Buffer>(netBuffer, Jin_Lua_Buffer));
+ return 1;
+ }
+
+ // Socket:receiveFrom(address, port)
+ LUA_IMPLEMENT int l_receiveFrom(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ int address = luax_checkinteger(L, 2);
+ int port = luax_checkinteger(L, 3);
+ char buffer[BUFFER_SIZE];
+ int size = socket->receiveFrom(buffer, BUFFER_SIZE, address, port);
+ Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer);
+ proxy->bind(new Shared<Buffer>(netBuffer, Jin_Lua_Buffer));
+ return 1;
+ }
+
+ // Socket:send(net.Buffer) -> data_length
+ LUA_IMPLEMENT int l_send(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ Shared<Buffer>& shared = checkNetBuffer(L, 2);
+ int len = socket->send(shared->buffer, shared->size);
+ luax_pushinteger(L, len);
+ return 1;
+ }
+
+ // Socket:sendTo(address, port, net.Buffer)
+ LUA_IMPLEMENT int l_sendTo(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ int address = luax_checkinteger(L, 2);
+ int port = luax_checkinteger(L, 3);
+ Shared<Buffer>& buffer = checkNetBuffer(L, 4);
+ socket->sendTo(buffer->buffer, buffer->size, address, port);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_close(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ socket->close();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_configBlocking(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ bool blocking = luax_checkbool(L, 2);
+ socket->configureBlocking(blocking);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Socket);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Socket(lua_State* L)
+ {
+ luaL_Reg socket_function[] = {
+ { "__gc", l_gc },
+ { "accept", l_accept },
+ { "receive", l_receive },
+ { "receiveFrom", l_receiveFrom },
+ { "send", l_send },
+ { "sendTo", l_sendTo },
+ { "close", l_close },
+ { "configBlocking", l_configBlocking },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Socket, socket_function);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/net/je_lua_socket.h b/src/lua/modules/net/je_lua_socket.h
new file mode 100644
index 0000000..b33fac6
--- /dev/null
+++ b/src/lua/modules/net/je_lua_socket.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_SOCKET_H__
+#define __JE_LUA_SOCKET_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Socket;
+
+ void luaopen_Socket(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/net/socket.cpp b/src/lua/modules/net/socket.cpp
deleted file mode 100644
index d6de730..0000000
--- a/src/lua/modules/net/socket.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-#include "Buffer.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Net;
- using namespace Lua::Net;
-
- typedef Ref<Socket>& SocketRef;
-
- const int BUFFER_SIZE = 1024;
-
- static inline SocketRef checkSocket(lua_State* L, int pos = 1)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, pos, JIN_NETWORK_SOCKET);
- return proxy->getRef<Socket>();
- }
-
- static inline Ref<Buffer>& checkNetBuffer(lua_State* L, int pos = 1)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, pos, JIN_NETWORK_BUFFER);
- return proxy->getRef<Buffer>();
- }
-
- // return net.Socket
- static int l_accept(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- Socket* client = socket->accept();
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy));
- proxy->bind(new Ref<Socket>(client, JIN_NETWORK_SOCKET));
- return 1;
- }
-
- // return net.Buffer
- static int l_receive(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- char buffer[BUFFER_SIZE] = {0};
- int size = socket->receive(buffer, BUFFER_SIZE);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
- Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
- proxy->bind(new Ref<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
- return 1;
- }
-
- // Socket:receiveFrom(address, port)
- static int l_receiveFrom(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- int address = luax_checkinteger(L, 2);
- int port = luax_checkinteger(L, 3);
- char buffer[BUFFER_SIZE];
- int size = socket->receiveFrom(buffer, BUFFER_SIZE, address, port);
- Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
- proxy->bind(new Ref<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
- return 1;
- }
-
- // Socket:send(net.Buffer) -> data_length
- static int l_send(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- Ref<Buffer>& ref = checkNetBuffer(L, 2);
- int len = socket->send(ref->buffer, ref->size);
- luax_pushinteger(L, len);
- return 1;
- }
-
- // Socket:sendTo(address, port, net.Buffer)
- static int l_sendTo(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- int address = luax_checkinteger(L, 2);
- int port = luax_checkinteger(L, 3);
- Ref<Buffer>& buffer = checkNetBuffer(L, 4);
- socket->sendTo(buffer->buffer, buffer->size, address, port);
- return 0;
- }
-
- static int l_close(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- socket->close();
- return 0;
- }
-
- static int l_configBlocking(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- bool blocking = luax_checkbool(L, 2);
- socket->configureBlocking(blocking);
- return 0;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_SOCKET);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg socket_function[] = {
- { "__gc", l_gc },
- { "accept", l_accept },
- { "receive", l_receive },
- { "receiveFrom", l_receiveFrom },
- { "send", l_send },
- { "sendTo", l_sendTo },
- { "close", l_close },
- { "configBlocking", l_configBlocking },
- { 0, 0 }
- };
-
- int luaopen_Socket(lua_State* L)
- {
- luax_newtype(L, JIN_NETWORK_SOCKET, socket_function);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/Thread.cpp b/src/lua/modules/thread/Thread.cpp
deleted file mode 100644
index e1c5a92..0000000
--- a/src/lua/modules/thread/Thread.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "libjin/jin.h"
-#include "lua/jin.h"
-#include "lua/common/common.h"
-#include "thread.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using thread::Thread;
-
- typedef Ref<Thread>& ThreadRef;
-
- int luaopen_thread(lua_State* L);
-
- static inline ThreadRef checkThread(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_THREAD_THREAD);
- return proxy->getRef<Thread>();
- }
-
- static int threadRunner(void* t)
- {
- ThreadRef 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)
- {
- ThreadRef ref = checkThread(L);
- bool result = ref->start(&ref);
- luax_pushboolean(L, result);
- return 1;
- }
-
- static int l_wait(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- ref->wait();
- return 0;
- }
-
- static int l_send(lua_State* L)
- {
- ThreadRef 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)
- {
- ThreadRef 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)
- {
- ThreadRef 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)
- {
- ThreadRef 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;
- const char* objType = p->getObjectType();
- Proxy* proxy = (Proxy*)luax_newinstance(L, objType, sizeof(Proxy));
- p->reference->retain();
- proxy->bind(p->reference);
- break;
-
- }
- return 1;
- }
-
- static int l_remove(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- ref->remove(slot);
- return 0;
- }
-
- static int l_getName(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- const char* name = ref->getName();
- luax_pushstring(L, name);
- return 1;
- }
-
- static int l_isRunning(lua_State* L)
- {
- ThreadRef 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;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/Thread.h b/src/lua/modules/thread/Thread.h
deleted file mode 100644
index 60d588a..0000000
--- a/src/lua/modules/thread/Thread.h
+++ /dev/null
@@ -1,94 +0,0 @@
-#include "libjin/jin.h"
-#include "lua/common/common.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
- namespace thread
- {
-
- class Thread
- {
- public:
- typedef JinEngine::MultiThread::Thread::Variant Variant;
- typedef JinEngine::MultiThread::Thread::ThreadRunner ThreadRunner;
-
- Thread(std::string _name, std::string _code, ThreadRunner runner)
- : name(_name)
- , code(_code)
- {
- thread = new JinEngine::MultiThread::Thread(_name, runner);
- }
-
- ~Thread()
- {
- delete thread;
- }
-
- bool start(void* p)
- {
- return thread->start(p);
- }
-
- void wait()
- {
- thread->wait();
- }
-
- void send(int slot, const Variant& value)
- {
- thread->send(slot, value);
- }
-
- bool receive(int slot)
- {
- return thread->receive(slot);
- }
-
- Variant fetch(int slot)
- {
- return thread->fetch(slot);
- }
-
- Variant demand(int slot)
- {
- return thread->demand(slot);
- }
-
- void remove(int slot)
- {
- thread->remove(slot);
- }
-
- const char* getName()
- {
- return name.c_str();
- }
-
- bool isRunning()
- {
- return thread->isRunning();
- }
-
- void lock()
- {
- thread->lock();
- }
-
- void unlock()
- {
- thread->unlock();
- }
-
- const std::string name;
- const std::string code;
-
- private:
- JinEngine::MultiThread::Thread* thread;
-
- };
-
- } // thread
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/je_lua_thread.cpp b/src/lua/modules/thread/je_lua_thread.cpp
new file mode 100644
index 0000000..d7b50ab
--- /dev/null
+++ b/src/lua/modules/thread/je_lua_thread.cpp
@@ -0,0 +1,248 @@
+#include "lua/modules/luax.h"
+
+#include "libjin/jin.h"
+#include "lua/jin.h"
+#include "lua/common/je_lua_common.h"
+#include "je_lua_thread.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Thread = "Thread";
+
+ typedef Shared<Thread>& SharedThread;
+
+ int luaopen_thread(lua_State* L);
+
+ static inline SharedThread checkThread(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Thread);
+ return proxy->getShared<Thread>();
+ }
+
+ LUA_IMPLEMENT int threadRunner(void* t)
+ {
+ SharedThread shared = *(Shared<Thread>*)t;
+ lua_State* L = lua_open();
+ luax_openlibs(L);
+ luaopen_jin(L);
+ luax_getglobal(L, MODULE_NAME);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread);
+ proxy->bind(&shared);
+ luax_setfield(L, -2, "_curThread");
+ luax_dostring(L, shared->code.c_str());
+ luax_close(L);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_thread_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Thread);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_start(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ bool result = shared->start(&shared);
+ luax_pushboolean(L, result);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_wait(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ shared->wait();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_send(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ const int vp = 3;
+ if (luax_isnumberstrict(L, vp))
+ {
+ float real = luax_checknumber(L, vp);
+ shared->send(slot, real);
+ }
+ else if (luax_isbooleanstrict(L, vp))
+ {
+ bool bol = luax_checkbool(L, vp);
+ shared->send(slot, bol);
+ }
+ else if (luax_isstringstrict(L, vp))
+ {
+ const char* str = luax_checkstring(L, vp);
+ shared->send(slot, str);
+ }
+ else if (luax_isuserdata(L, vp))
+ {
+ void* p = luax_touserdata(L, vp);
+ shared->send(slot, p);
+ }
+ else if (luax_islightuserdata(L, vp))
+ {
+ void* p = luax_tolightuserdata(L, vp);
+ shared->send(slot, p);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_receive(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ bool result = shared->receive(slot);
+ luax_pushboolean(L, result);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_fetch(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ Thread::Variant v = shared->fetch(slot);
+ switch (v.type)
+ {
+ case Thread::Variant::INTERGER:
+ luax_pushinteger(L, v.integer);
+ break;
+
+ case Thread::Variant::BOOLEAN:
+ luax_pushboolean(L, v.boolean);
+ break;
+
+ case Thread::Variant::CSTRING:
+ luax_pushstring(L, v.cstring);
+ break;
+
+ case Thread::Variant::REAL:
+ luax_pushnumber(L, v.real);
+ break;
+
+ case Thread::Variant::POINTER:
+ Proxy* p = (Proxy*)v.pointer;
+ Proxy* proxy = luax_newinstance(L, p->getObjectType());
+ proxy->bind(p->shared);
+ break;
+
+ }
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_demand(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ Thread::Variant v = shared->demand(slot);
+ switch (v.type)
+ {
+ case Thread::Variant::INTERGER:
+ luax_pushinteger(L, v.integer);
+ break;
+
+ case Thread::Variant::BOOLEAN:
+ luax_pushboolean(L, v.boolean);
+ break;
+
+ case Thread::Variant::CSTRING:
+ luax_pushstring(L, v.cstring);
+ break;
+
+ case Thread::Variant::REAL:
+ luax_pushnumber(L, v.real);
+ break;
+
+ case Thread::Variant::POINTER:
+ Proxy* p = (Proxy*)v.pointer;
+ const char* objType = p->getObjectType();
+ Proxy* proxy = luax_newinstance(L, objType);
+ proxy->bind(p->shared);
+ break;
+
+ }
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_remove(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ shared->remove(slot);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getName(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ const char* name = shared->getName();
+ luax_pushstring(L, name);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_isRunning(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ bool running = shared->isRunning();
+ luax_pushboolean(L, running);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int luaopen_Thread(lua_State* L)
+ {
+ 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 }
+ };
+
+ luax_newtype(L, Jin_Lua_Thread, thread_function);
+
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newThread(lua_State* L)
+ {
+ const char* name = luax_checkstring(L, 1);
+ const char* code = luax_checkstring(L, 2);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread);
+ Thread* thread = new Thread(name, code, threadRunner);
+ proxy->bind(new Shared<Thread>(thread, Jin_Lua_Thread));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getThread(lua_State* L)
+ {
+ luax_getglobal(L, MODULE_NAME);
+ luax_getfield(L, -1, "_curThread");
+ return 1;
+ }
+
+ LUA_EXPORT int luaopen_thread(lua_State* L)
+ {
+ luaopen_Thread(L);
+
+ luaL_Reg f[] = {
+ { "newThread", l_newThread },
+ { "getThread", l_getThread },
+ { 0, 0 }
+ };
+ luax_newlib(L, f);
+
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/je_lua_thread.h b/src/lua/modules/thread/je_lua_thread.h
new file mode 100644
index 0000000..a3e4e76
--- /dev/null
+++ b/src/lua/modules/thread/je_lua_thread.h
@@ -0,0 +1,93 @@
+#include "libjin/jin.h"
+#include "lua/common/je_lua_common.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Thread;
+
+ class Thread
+ {
+ public:
+ typedef JinEngine::Threads::Thread::Variant Variant;
+ typedef JinEngine::Threads::Thread::ThreadRunner ThreadRunner;
+
+ Thread(std::string _name, std::string _code, ThreadRunner runner)
+ : name(_name)
+ , code(_code)
+ {
+ thread = new JinEngine::Threads::Thread(_name, runner);
+ }
+
+ ~Thread()
+ {
+ delete thread;
+ }
+
+ bool start(void* p)
+ {
+ return thread->start(p);
+ }
+
+ void wait()
+ {
+ thread->wait();
+ }
+
+ void send(int slot, const Variant& value)
+ {
+ thread->send(slot, value);
+ }
+
+ bool receive(int slot)
+ {
+ return thread->receive(slot);
+ }
+
+ Variant fetch(int slot)
+ {
+ return thread->fetch(slot);
+ }
+
+ Variant demand(int slot)
+ {
+ return thread->demand(slot);
+ }
+
+ void remove(int slot)
+ {
+ thread->remove(slot);
+ }
+
+ const char* getName()
+ {
+ return name.c_str();
+ }
+
+ bool isRunning()
+ {
+ return thread->isRunning();
+ }
+
+ void lock()
+ {
+ thread->lock();
+ }
+
+ void unlock()
+ {
+ thread->unlock();
+ }
+
+ const std::string name;
+ const std::string code;
+
+ private:
+ JinEngine::Threads::Thread* thread;
+
+ };
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/time/je_lua_time.cpp b/src/lua/modules/time/je_lua_time.cpp
new file mode 100644
index 0000000..39ec899
--- /dev/null
+++ b/src/lua/modules/time/je_lua_time.cpp
@@ -0,0 +1,71 @@
+#include "SDL2/SDL.h"
+#include "lua/common/je_lua_common.h"
+#include "lua/modules/luax.h"
+#include "libjin/jin.h"
+
+
+#include "je_lua_timer.h"
+
+using namespace JinEngine::Time;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ static struct
+ {
+ float previous;
+ float current;
+ } context;
+
+ LUA_IMPLEMENT int l_sec(lua_State* L)
+ {
+ luax_pushnumber(L, getSecond());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_sleep(lua_State* L)
+ {
+ double sec = luax_checknumber(L, 1);
+ sleep(sec * 1000.0f);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newTimer(lua_State* L)
+ {
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Timer);
+ proxy->bind(new Shared<Timer>(new Timer(), Jin_Lua_Timer));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getDelta(lua_State* L)
+ {
+ luax_pushnumber(L, context.current - context.previous);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_step(lua_State* L)
+ {
+ context.previous = context.current;
+ context.current = getSecond();
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_time(lua_State* L)
+ {
+ luaopen_Timer(L);
+ luaL_Reg f[] = {
+ { "second", l_sec },
+ { "sleep", l_sleep },
+ { "newTimer", l_newTimer },
+ { "step", l_step },
+ { "getDelta", l_getDelta },
+ { 0, 0 },
+ };
+ luax_newlib(L, f);
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/time/je_lua_time.h b/src/lua/modules/time/je_lua_time.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/time/je_lua_time.h
diff --git a/src/lua/modules/time/je_lua_timer.cpp b/src/lua/modules/time/je_lua_timer.cpp
new file mode 100644
index 0000000..540f205
--- /dev/null
+++ b/src/lua/modules/time/je_lua_timer.cpp
@@ -0,0 +1,146 @@
+
+#include "lua/common/je_lua_callback.h"
+#include "lua/common/je_lua_common.h"
+#include "je_lua_timer.h"
+
+using namespace JinEngine::Time;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Timer = "Timer";
+
+ const char* Jin_Lua_Handler = "Handler";
+
+ typedef Shared<Timer>& SharedTimer;
+
+ static Timer::TimerCallback timerCallback = [](void* data)->void
+ {
+ LuaCallback* func = static_cast<LuaCallback*>(data);
+ func->call();
+ };
+
+ static Timer::FinishCallback finishCallback = [](void* data)->void
+ {
+ LuaCallback* func = static_cast<LuaCallback*>(data);
+ delete func;
+ };
+
+ LUA_IMPLEMENT inline SharedTimer checkTimer(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ return proxy->getShared<Timer>();
+ }
+
+ // timer:every(time, callback, parameter)
+ LUA_IMPLEMENT int l_every(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(3);
+ for(int i = 4; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->every(s, timerCallback, func, finishCallback);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler);
+ Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler);
+ shrHandler->retain();
+ proxy->bind(shrHandler);
+ return 1;
+ }
+
+ // timer:after(time, callback, parameter)
+ LUA_IMPLEMENT int l_after(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(3);
+ for (int i = 4; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->after(s, timerCallback, func, finishCallback);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler);
+ Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler);
+ shrHandler->retain();
+ proxy->bind(shrHandler);
+ return 1;
+ }
+
+ // timer:repeat(time, callback, parameter)
+ LUA_IMPLEMENT int l_repeat(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ int count = luax_checkinteger(L, 3);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(4);
+ for (int i = 5; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->repeat(s, count, timerCallback, func, finishCallback);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler);
+ Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler);
+ shrHandler->retain();
+ proxy->bind(shrHandler);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_update(lua_State* L)
+ {
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ timer->update(s);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_cancel(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ Timer* timer = p->getObject<Timer>();
+ Proxy* ph = (Proxy*)luax_checktype(L, 2, Jin_Lua_Handler);
+ Timer::Handler* handler = ph->getObject<Timer::Handler>();
+ timer->cancel(handler);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_cancelAll(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ Timer* timer = p->getObject<Timer>();
+ timer->cancelAll();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ p->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Timer(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "every", l_every },
+ { "after", l_after },
+ { "duplicate", l_repeat },
+ { "update", l_update },
+ { "cancel", l_cancel },
+ { "cancelAll", l_cancelAll },
+ { 0, 0 }
+ };
+
+ luax_newtype(L, Jin_Lua_Timer, f);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/time/je_lua_timer.h b/src/lua/modules/time/je_lua_timer.h
new file mode 100644
index 0000000..35ec15d
--- /dev/null
+++ b/src/lua/modules/time/je_lua_timer.h
@@ -0,0 +1,20 @@
+#ifndef __JE_LUA_TIMER_H__
+#define __JE_LUA_TIMER_H__
+
+#include "libjin/jin.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Timer;
+
+ extern const char* Jin_Lua_Handler;
+
+ void luaopen_Timer(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/time/time.cpp b/src/lua/modules/time/time.cpp
deleted file mode 100644
index f6e6f26..0000000
--- a/src/lua/modules/time/time.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "lua/modules/luax.h"
-#include <SDL2/SDL.h>
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Time;
-
- static int l_sec(lua_State* L)
- {
- luax_pushnumber(L, getSecond());
- return 1;
- }
-
- static int l_sleep(lua_State* L)
- {
- double sec = luax_checknumber(L, 1);
- sleep(sec * 1000.0f);
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "second", l_sec },
- { "sleep", l_sleep },
- { 0, 0 },
- };
-
- int luaopen_time(lua_State* L)
- {
- luax_newlib(L, f);
- return 1;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/types.h b/src/lua/modules/types.h
deleted file mode 100644
index 123604e..0000000
--- a/src/lua/modules/types.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef __JIN_MODULES_TYPES_H
-#define __JIN_MODULES_TYPES_H
-
-// graphics module
-#define JIN_GRAPHICS_TEXTURE "Texture"
-#define JIN_GRAPHICS_SHADER "Shader"
-#define JIN_GRAPHICS_CANVAS "Canvas"
-#define JIN_GRAPHICS_TEXT "Text"
-#define JIN_GRAPHICS_TTFDATA "TTFData"
-#define JIN_GRAPHICS_TTF "TTF"
-#define JIN_GRAPHICS_TEXTUREFONT "TextureFont"
-#define JIN_GRAPHICS_PAGE "Page"
-#define JIN_GRAPHICS_BITMAP "Bitmap"
-
-// audio module
-#define JIN_AUDIO_SOURCE "Source"
-
-// thread module
-#define JIN_THREAD_THREAD "Thread"
-
-// network module
-#define JIN_NETWORK_SOCKET "Socket"
-#define JIN_NETWORK_BUFFER "Buffer"
-
-#endif \ No newline at end of file