aboutsummaryrefslogtreecommitdiff
path: root/src/libjin-lua/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin-lua/modules')
-rw-r--r--src/libjin-lua/modules/ai/l_ai.cpp6
-rw-r--r--src/libjin-lua/modules/ai/l_ai.h8
-rw-r--r--src/libjin-lua/modules/ai/l_behavior_tree.cpp8
-rw-r--r--src/libjin-lua/modules/ai/l_behavior_tree.h8
-rw-r--r--src/libjin-lua/modules/ai/l_state_machine.cpp26
-rw-r--r--src/libjin-lua/modules/ai/l_state_machine.h8
-rw-r--r--src/libjin-lua/modules/audio/l_source.cpp186
-rw-r--r--src/libjin-lua/modules/audio/l_source.h10
-rw-r--r--src/libjin-lua/modules/bit/l_bit.cpp134
-rw-r--r--src/libjin-lua/modules/bit/l_bit.h8
-rw-r--r--src/libjin-lua/modules/core/l_core.cpp74
-rw-r--r--src/libjin-lua/modules/core/l_core.h8
-rw-r--r--src/libjin-lua/modules/event/l_event.cpp210
-rw-r--r--src/libjin-lua/modules/event/l_event.h8
-rw-r--r--src/libjin-lua/modules/filesystem/l_filesystem.h8
-rw-r--r--src/libjin-lua/modules/graphics/l_animation.cpp186
-rw-r--r--src/libjin-lua/modules/graphics/l_animation.h24
-rw-r--r--src/libjin-lua/modules/graphics/l_animator.cpp288
-rw-r--r--src/libjin-lua/modules/graphics/l_animator.h18
-rw-r--r--src/libjin-lua/modules/graphics/l_bitmap.cpp178
-rw-r--r--src/libjin-lua/modules/graphics/l_bitmap.h10
-rw-r--r--src/libjin-lua/modules/graphics/l_canvas.cpp106
-rw-r--r--src/libjin-lua/modules/graphics/l_canvas.h10
-rw-r--r--src/libjin-lua/modules/graphics/l_graphics.h8
-rw-r--r--src/libjin-lua/modules/graphics/l_mesh.cpp134
-rw-r--r--src/libjin-lua/modules/graphics/l_mesh.h18
-rw-r--r--src/libjin-lua/modules/graphics/l_page.cpp90
-rw-r--r--src/libjin-lua/modules/graphics/l_page.h20
-rw-r--r--src/libjin-lua/modules/graphics/l_particle_system.cpp810
-rw-r--r--src/libjin-lua/modules/graphics/l_particle_system.h18
-rw-r--r--src/libjin-lua/modules/graphics/l_shader.cpp214
-rw-r--r--src/libjin-lua/modules/graphics/l_shader.h10
-rw-r--r--src/libjin-lua/modules/graphics/l_sprite.cpp88
-rw-r--r--src/libjin-lua/modules/graphics/l_sprite.h24
-rw-r--r--src/libjin-lua/modules/graphics/l_spritesheet.cpp194
-rw-r--r--src/libjin-lua/modules/graphics/l_spritesheet.h18
-rw-r--r--src/libjin-lua/modules/graphics/l_text.cpp36
-rw-r--r--src/libjin-lua/modules/graphics/l_text.h10
-rw-r--r--src/libjin-lua/modules/graphics/l_texture.cpp106
-rw-r--r--src/libjin-lua/modules/graphics/l_texture.h10
-rw-r--r--src/libjin-lua/modules/graphics/l_texture_font.cpp100
-rw-r--r--src/libjin-lua/modules/graphics/l_texture_font.h10
-rw-r--r--src/libjin-lua/modules/graphics/l_ttf.cpp100
-rw-r--r--src/libjin-lua/modules/graphics/l_ttf.h10
-rw-r--r--src/libjin-lua/modules/graphics/l_ttf_data.cpp72
-rw-r--r--src/libjin-lua/modules/graphics/l_ttf_data.h18
-rw-r--r--src/libjin-lua/modules/joypad/l_joypad.cpp24
-rw-r--r--src/libjin-lua/modules/joypad/l_joypad.h8
-rw-r--r--src/libjin-lua/modules/keyboard/l_keyboard.cpp18
-rw-r--r--src/libjin-lua/modules/keyboard/l_keyboard.h8
-rw-r--r--src/libjin-lua/modules/math/l_math.cpp40
-rw-r--r--src/libjin-lua/modules/math/l_math.h8
-rw-r--r--src/libjin-lua/modules/mouse/l_mouse.cpp60
-rw-r--r--src/libjin-lua/modules/mouse/l_mouse.h8
-rw-r--r--src/libjin-lua/modules/net/l_buffer.cpp230
-rw-r--r--src/libjin-lua/modules/net/l_buffer.h180
-rw-r--r--src/libjin-lua/modules/net/l_net.cpp128
-rw-r--r--src/libjin-lua/modules/net/l_net.h8
-rw-r--r--src/libjin-lua/modules/net/l_socket.cpp204
-rw-r--r--src/libjin-lua/modules/net/l_socket.h10
-rw-r--r--src/libjin-lua/modules/thread/l_thread.cpp460
-rw-r--r--src/libjin-lua/modules/thread/l_thread.h178
-rw-r--r--src/libjin-lua/modules/time/l_time.cpp94
-rw-r--r--src/libjin-lua/modules/time/l_time.h8
-rw-r--r--src/libjin-lua/modules/time/l_timer.cpp246
-rw-r--r--src/libjin-lua/modules/time/l_timer.h14
66 files changed, 2791 insertions, 2791 deletions
diff --git a/src/libjin-lua/modules/ai/l_ai.cpp b/src/libjin-lua/modules/ai/l_ai.cpp
index 4afd625..0b3ac85 100644
--- a/src/libjin-lua/modules/ai/l_ai.cpp
+++ b/src/libjin-lua/modules/ai/l_ai.cpp
@@ -4,10 +4,10 @@ using namespace JinEngine::AI;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- }
+ }
} \ No newline at end of file
diff --git a/src/libjin-lua/modules/ai/l_ai.h b/src/libjin-lua/modules/ai/l_ai.h
index 919c0a3..eaee6b9 100644
--- a/src/libjin-lua/modules/ai/l_ai.h
+++ b/src/libjin-lua/modules/ai/l_ai.h
@@ -6,12 +6,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_ai(lua_State* L);
+ int luaopen_ai(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/ai/l_behavior_tree.cpp b/src/libjin-lua/modules/ai/l_behavior_tree.cpp
index 20e8e55..8027c5f 100644
--- a/src/libjin-lua/modules/ai/l_behavior_tree.cpp
+++ b/src/libjin-lua/modules/ai/l_behavior_tree.cpp
@@ -2,10 +2,10 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- const char* Jin_Lua_BehaviorTree = "Texture";
+ const char* Jin_Lua_BehaviorTree = "Texture";
- }
+ }
} \ No newline at end of file
diff --git a/src/libjin-lua/modules/ai/l_behavior_tree.h b/src/libjin-lua/modules/ai/l_behavior_tree.h
index 083d12b..faace67 100644
--- a/src/libjin-lua/modules/ai/l_behavior_tree.h
+++ b/src/libjin-lua/modules/ai/l_behavior_tree.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_BehaviorTree;
+ extern const char* Jin_Lua_BehaviorTree;
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/ai/l_state_machine.cpp b/src/libjin-lua/modules/ai/l_state_machine.cpp
index 1825de5..8095bfb 100644
--- a/src/libjin-lua/modules/ai/l_state_machine.cpp
+++ b/src/libjin-lua/modules/ai/l_state_machine.cpp
@@ -5,21 +5,21 @@ using namespace JinEngine::AI;
namespace JinEngine
{
- namespace Lua
- {
-
- const char* Jin_Lua_StateMachine = "StateMachine";
+ namespace Lua
+ {
+
+ const char* Jin_Lua_StateMachine = "StateMachine";
- LUA_IMPLEMENT int l_addEnterCallback(lua_State* L)
- {
- //StateMachine* sm;
- //sm->addEnterListener("", [](void* p) -> void{
+ LUA_IMPLEMENT int l_addEnterCallback(lua_State* L)
+ {
+ //StateMachine* sm;
+ //sm->addEnterListener("", [](void* p) -> void{
- //
- //});
+ //
+ //});
- return 0;
- }
+ return 0;
+ }
- }
+ }
} \ No newline at end of file
diff --git a/src/libjin-lua/modules/ai/l_state_machine.h b/src/libjin-lua/modules/ai/l_state_machine.h
index 3c78f75..772531e 100644
--- a/src/libjin-lua/modules/ai/l_state_machine.h
+++ b/src/libjin-lua/modules/ai/l_state_machine.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_StateMachine;
+ extern const char* Jin_Lua_StateMachine;
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/audio/l_source.cpp b/src/libjin-lua/modules/audio/l_source.cpp
index 72af871..29b928b 100644
--- a/src/libjin-lua/modules/audio/l_source.cpp
+++ b/src/libjin-lua/modules/audio/l_source.cpp
@@ -6,109 +6,109 @@ using namespace JinEngine::Audio;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- const char* Jin_Lua_Source = "Source";
-
- LUA_IMPLEMENT inline Source* checkSource(lua_State* L)
- {
- LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_Source);
- Source* source = luaObj->getObject<Source>();
- return source;
- }
+ const char* Jin_Lua_Source = "Source";
+
+ LUA_IMPLEMENT inline Source* checkSource(lua_State* L)
+ {
+ LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_Source);
+ Source* source = luaObj->getObject<Source>();
+ return source;
+ }
- LUA_IMPLEMENT int l_play(lua_State* L)
- {
- Source* source = checkSource(L);
- source->play();
- return 0;
- }
+ LUA_IMPLEMENT int l_play(lua_State* L)
+ {
+ Source* source = checkSource(L);
+ source->play();
+ return 0;
+ }
- LUA_IMPLEMENT int l_stop(lua_State* L)
- {
- Source* source = checkSource(L);
- source->stop();
- return 0;
- }
+ LUA_IMPLEMENT int l_stop(lua_State* L)
+ {
+ Source* source = checkSource(L);
+ source->stop();
+ return 0;
+ }
- LUA_IMPLEMENT int l_pause(lua_State* L)
- {
- Source* source = checkSource(L);
- source->pause();
- return 0;
- }
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ Source* source = checkSource(L);
+ source->pause();
+ return 0;
+ }
- LUA_IMPLEMENT int l_rewind(lua_State* L)
- {
- Source* source = checkSource(L);
- source->rewind();
- return 0;
- }
+ LUA_IMPLEMENT int l_rewind(lua_State* L)
+ {
+ Source* source = checkSource(L);
+ source->rewind();
+ return 0;
+ }
- LUA_IMPLEMENT int l_resume(lua_State* L)
- {
- Source* source = checkSource(L);
- source->resume();
- return 0;
- }
+ LUA_IMPLEMENT int l_resume(lua_State* L)
+ {
+ Source* source = checkSource(L);
+ source->resume();
+ return 0;
+ }
- LUA_IMPLEMENT int l_isStop(lua_State* L)
- {
- Source* source = checkSource(L);
- bool isStop = source->isStopped();
- luax_pushboolean(L, isStop);
- return 1;
- }
+ LUA_IMPLEMENT int l_isStop(lua_State* L)
+ {
+ Source* source = checkSource(L);
+ bool isStop = source->isStopped();
+ luax_pushboolean(L, isStop);
+ return 1;
+ }
- LUA_IMPLEMENT int l_isPaused(lua_State* L)
- {
- Source* source = checkSource(L);
- bool isPaused = source->isPaused();
- luax_pushboolean(L, isPaused);
- return 1;
- }
+ LUA_IMPLEMENT int l_isPaused(lua_State* L)
+ {
+ Source* source = checkSource(L);
+ bool isPaused = source->isPaused();
+ luax_pushboolean(L, isPaused);
+ return 1;
+ }
- LUA_IMPLEMENT int l_setVolume(lua_State* L)
- {
- Source* source = checkSource(L);
- float volume = luax_checknumber(L, 2);
- source->setVolume(volume);
- return 0;
- }
+ LUA_IMPLEMENT int l_setVolume(lua_State* L)
+ {
+ Source* source = checkSource(L);
+ float volume = luax_checknumber(L, 2);
+ source->setVolume(volume);
+ return 0;
+ }
- LUA_IMPLEMENT int l_setLoop(lua_State* L)
- {
- Source* source = checkSource(L);
- bool loop = luax_checkbool(L, 2);
- source->setLoop(loop);
- return 0;
- }
+ LUA_IMPLEMENT int l_setLoop(lua_State* L)
+ {
+ Source* source = checkSource(L);
+ bool loop = luax_checkbool(L, 2);
+ source->setLoop(loop);
+ return 0;
+ }
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Source);
- luaObj->release();
- return 0;
- }
-
- LUA_EXPORT void luaopen_Source(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__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, methods);
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Source);
+ luaObj->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Source(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__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, methods);
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/audio/l_source.h b/src/libjin-lua/modules/audio/l_source.h
index f7e6b48..eee3439 100644
--- a/src/libjin-lua/modules/audio/l_source.h
+++ b/src/libjin-lua/modules/audio/l_source.h
@@ -3,14 +3,14 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_Source;
+ extern const char* Jin_Lua_Source;
- void luaopen_Source(lua_State* L);
+ void luaopen_Source(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/bit/l_bit.cpp b/src/libjin-lua/modules/bit/l_bit.cpp
index 43be892..2e4a3a6 100644
--- a/src/libjin-lua/modules/bit/l_bit.cpp
+++ b/src/libjin-lua/modules/bit/l_bit.cpp
@@ -6,81 +6,81 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- LUA_IMPLEMENT int l_and(lua_State* L)
- {
- int a = luax_checkinteger(L, 1);
- int b = luax_checkinteger(L, 2);
- luax_pushinteger(L, a & b);
- return 1;
- }
+ LUA_IMPLEMENT int l_and(lua_State* L)
+ {
+ int a = luax_checkinteger(L, 1);
+ int b = luax_checkinteger(L, 2);
+ luax_pushinteger(L, a & b);
+ return 1;
+ }
- LUA_IMPLEMENT int l_or(lua_State* L)
- {
- int a = luax_checkinteger(L, 1);
- int b = luax_checkinteger(L, 2);
- luax_pushinteger(L, a | b);
- return 1;
- }
+ LUA_IMPLEMENT int l_or(lua_State* L)
+ {
+ int a = luax_checkinteger(L, 1);
+ int b = luax_checkinteger(L, 2);
+ luax_pushinteger(L, a | b);
+ return 1;
+ }
- LUA_IMPLEMENT int l_xor(lua_State* L)
- {
- int a = luax_checkinteger(L, 1);
- int b = luax_checkinteger(L, 2);
- luax_pushinteger(L, a ^ b);
- return 1;
- }
+ LUA_IMPLEMENT int l_xor(lua_State* L)
+ {
+ int a = luax_checkinteger(L, 1);
+ int b = luax_checkinteger(L, 2);
+ luax_pushinteger(L, a ^ b);
+ return 1;
+ }
- LUA_IMPLEMENT int l_not(lua_State* L)
- {
- int n = luax_checkinteger(L, 1);
- luax_pushinteger(L, ~n);
- return 1;
- }
+ LUA_IMPLEMENT int l_not(lua_State* L)
+ {
+ int n = luax_checkinteger(L, 1);
+ luax_pushinteger(L, ~n);
+ return 1;
+ }
- LUA_IMPLEMENT int l_lshift(lua_State* L)
- {
- int a = luax_checkinteger(L, 1);
- int b = luax_checkinteger(L, 2);
- luax_pushinteger(L, a << b);
- return 1;
- }
+ LUA_IMPLEMENT int l_lshift(lua_State* L)
+ {
+ int a = luax_checkinteger(L, 1);
+ int b = luax_checkinteger(L, 2);
+ luax_pushinteger(L, a << b);
+ return 1;
+ }
- LUA_IMPLEMENT int l_rshift(lua_State* L)
- {
- int a = luax_checkinteger(L, 1);
- int b = luax_checkinteger(L, 2);
- luax_pushinteger(L, a >> b);
- return 1;
- }
+ LUA_IMPLEMENT int l_rshift(lua_State* L)
+ {
+ int a = luax_checkinteger(L, 1);
+ int b = luax_checkinteger(L, 2);
+ luax_pushinteger(L, a >> b);
+ return 1;
+ }
- LUA_IMPLEMENT int l_include(lua_State* L)
- {
- int a = luax_checkinteger(L, 1);
- int b = luax_checkinteger(L, 2);
- luax_pushboolean(L, (a & b) == b);
- return 1;
- }
-
- LUA_EXPORT int luaopen_bit(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "bAnd", l_and },
- { "bOr" , l_or },
- { "bXor", l_xor },
- { "bNot", l_not },
- { "bLs", l_lshift },
- { "bRs", l_rshift },
- { "bInc", l_include },
- { 0, 0 }
- };
+ LUA_IMPLEMENT int l_include(lua_State* L)
+ {
+ int a = luax_checkinteger(L, 1);
+ int b = luax_checkinteger(L, 2);
+ luax_pushboolean(L, (a & b) == b);
+ return 1;
+ }
+
+ LUA_EXPORT int luaopen_bit(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "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, methods);
+ luax_newlib(L, methods);
- return 1;
- }
+ return 1;
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/bit/l_bit.h b/src/libjin-lua/modules/bit/l_bit.h
index 21cf064..31d3585 100644
--- a/src/libjin-lua/modules/bit/l_bit.h
+++ b/src/libjin-lua/modules/bit/l_bit.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_bit(lua_State* L);
+ int luaopen_bit(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/core/l_core.cpp b/src/libjin-lua/modules/core/l_core.cpp
index 68b8156..6935179 100644
--- a/src/libjin-lua/modules/core/l_core.cpp
+++ b/src/libjin-lua/modules/core/l_core.cpp
@@ -6,41 +6,41 @@ 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 methods[] = {
- { "running", l_running },
- { "stop", l_stop },
- { "quit", l_quit },
- { 0, 0 }
- };
- luax_newlib(L, methods);
-
- return 1;
- }
-
- } // namespace Lua
+ 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 methods[] = {
+ { "running", l_running },
+ { "stop", l_stop },
+ { "quit", l_quit },
+ { 0, 0 }
+ };
+ luax_newlib(L, methods);
+
+ return 1;
+ }
+
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/core/l_core.h b/src/libjin-lua/modules/core/l_core.h
index 037ac4b..86b20a4 100644
--- a/src/libjin-lua/modules/core/l_core.h
+++ b/src/libjin-lua/modules/core/l_core.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_core(lua_State* L);
+ int luaopen_core(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/event/l_event.cpp b/src/libjin-lua/modules/event/l_event.cpp
index 8287238..c9d6a13 100644
--- a/src/libjin-lua/modules/event/l_event.cpp
+++ b/src/libjin-lua/modules/event/l_event.cpp
@@ -10,121 +10,121 @@ using namespace JinEngine::Input;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- /**
- * Load event poll, return a iterator(a table).
- */
- LUA_IMPLEMENT int l_event_poll(lua_State *L)
- {
- /* table to store events */
- luax_newtable(L);
- static Event e;
- int i = 1;
- poll:
- while (pollEvent(&e))
- {
- /**
- * TODO: ڴСıʱҪtransform
- *
- */
- luax_newtable(L);
- switch (e.type)
- {
- case EventType::QUIT:
- luax_setfieldstring(L, "type", "Quit");
- break;
+ /**
+ * Load event poll, return a iterator(a table).
+ */
+ LUA_IMPLEMENT int l_event_poll(lua_State *L)
+ {
+ /* table to store events */
+ luax_newtable(L);
+ static Event e;
+ int i = 1;
+ poll:
+ while (pollEvent(&e))
+ {
+ /**
+ * TODO: ڴСıʱҪtransform
+ *
+ */
+ luax_newtable(L);
+ switch (e.type)
+ {
+ case EventType::QUIT:
+ luax_setfieldstring(L, "type", "Quit");
+ break;
- case EventType::KEY_DOWN:
- case EventType::KEY_UP:
- luax_setfieldstring(L, "type", e.type == EventType::KEY_DOWN ? "KeyDown" : "KeyUp");
- luax_setfieldstring(L, "key", getKeyName(e.key.keysym.sym));
- break;
-
- case EventType::MOUSE_MOTION:
- luax_setfieldstring(L, "type", "MouseMotion");
- luax_setfieldnumber(L, "x", e.motion.x);
- luax_setfieldnumber(L, "y", e.motion.y);
- break;
-
- case EventType::MOUSE_BUTTON_DOWN:
- case EventType::MOUSE_BUTTON_UP:
- luax_setfieldstring(L, "type", e.type == EventType::MOUSE_BUTTON_DOWN ? "MouseButtonDown" : "MouseButtonUp");
- luax_setfieldstring(L, "button", getButtonName(e.button.button));
- luax_setfieldnumber(L, "x", e.button.x);
- luax_setfieldnumber(L, "y", e.button.y);
- break;
-
- case EventType::MOUSE_WHEEL:
- luax_setfieldstring(L, "type", "Wheel");
- if(e.wheel.x == -1)
- luax_setfieldstring(L, "x", "Left");
- else if(e.wheel.x == 1)
- luax_setfieldstring(L, "x", "Right");
- else
- luax_setfieldstring(L, "x", "None");
- if (e.wheel.y == -1)
- luax_setfieldstring(L, "y", "Near");
- else if (e.wheel.y == 1)
- luax_setfieldstring(L, "y", "Far");
- else
- luax_setfieldstring(L, "y", "None");
- break;
-
- case EventType::JOYBUTTONDOWN:
- case EventType::JOYBUTTONUP:
- luax_setfieldstring(L, "type", e.type == EventType::JOYBUTTONDOWN ? "JoyButtonDown" : "JoyButtonUp");
- luax_setfieldinteger(L, "which", e.jbutton.which);
- luax_setfieldstring(L, "button", Input::getJoyButtonName(e.jbutton.button));
- break;
+ case EventType::KEY_DOWN:
+ case EventType::KEY_UP:
+ luax_setfieldstring(L, "type", e.type == EventType::KEY_DOWN ? "KeyDown" : "KeyUp");
+ luax_setfieldstring(L, "key", getKeyName(e.key.keysym.sym));
+ break;
+
+ case EventType::MOUSE_MOTION:
+ luax_setfieldstring(L, "type", "MouseMotion");
+ luax_setfieldnumber(L, "x", e.motion.x);
+ luax_setfieldnumber(L, "y", e.motion.y);
+ break;
+
+ case EventType::MOUSE_BUTTON_DOWN:
+ case EventType::MOUSE_BUTTON_UP:
+ luax_setfieldstring(L, "type", e.type == EventType::MOUSE_BUTTON_DOWN ? "MouseButtonDown" : "MouseButtonUp");
+ luax_setfieldstring(L, "button", getButtonName(e.button.button));
+ luax_setfieldnumber(L, "x", e.button.x);
+ luax_setfieldnumber(L, "y", e.button.y);
+ break;
+
+ case EventType::MOUSE_WHEEL:
+ luax_setfieldstring(L, "type", "Wheel");
+ if(e.wheel.x == -1)
+ luax_setfieldstring(L, "x", "Left");
+ else if(e.wheel.x == 1)
+ luax_setfieldstring(L, "x", "Right");
+ else
+ luax_setfieldstring(L, "x", "None");
+ if (e.wheel.y == -1)
+ luax_setfieldstring(L, "y", "Near");
+ else if (e.wheel.y == 1)
+ luax_setfieldstring(L, "y", "Far");
+ else
+ luax_setfieldstring(L, "y", "None");
+ break;
+
+ case EventType::JOYBUTTONDOWN:
+ case EventType::JOYBUTTONUP:
+ luax_setfieldstring(L, "type", e.type == EventType::JOYBUTTONDOWN ? "JoyButtonDown" : "JoyButtonUp");
+ luax_setfieldinteger(L, "which", e.jbutton.which);
+ luax_setfieldstring(L, "button", Input::getJoyButtonName(e.jbutton.button));
+ break;
- case EventType::JOYAXISMOTION:
- luax_setfieldstring(L, "type", "JoyAxisMotion");
- luax_setfieldinteger(L, "which", e.jaxis.which);
- luax_setfieldfstring(L, "axis", Input::getJoyAxisName(e.jaxis.axis));
- break;
+ case EventType::JOYAXISMOTION:
+ luax_setfieldstring(L, "type", "JoyAxisMotion");
+ luax_setfieldinteger(L, "which", e.jaxis.which);
+ luax_setfieldfstring(L, "axis", Input::getJoyAxisName(e.jaxis.axis));
+ break;
- case EventType::JOYBALLMOTION:
- case EventType::JOYHATMOTION:
+ case EventType::JOYBALLMOTION:
+ case EventType::JOYHATMOTION:
- case EventType::JOYDEVICEADDED:
- case EventType::JOYDEVICEREMOVED:
- luax_setfieldfstring(L, "type", e.type == EventType::JOYDEVICEADDED ? "JoyDeviceAdded" : "JoyDeviceRemoved");
- luax_setfieldinteger(L, "which", e.jdevice.which);
- break;
+ case EventType::JOYDEVICEADDED:
+ case EventType::JOYDEVICEREMOVED:
+ luax_setfieldfstring(L, "type", e.type == EventType::JOYDEVICEADDED ? "JoyDeviceAdded" : "JoyDeviceRemoved");
+ luax_setfieldinteger(L, "which", e.jdevice.which);
+ break;
- //https://stackoverflow.com/questions/50022316/what-is-sdl-joystick-and-what-is-sdl-gamecontroller-what-are-the-relationships
- case EventType::CONTROLLERBUTTONDOWN:
- case EventType::CONTROLLERBUTTONUP:
+ //https://stackoverflow.com/questions/50022316/what-is-sdl-joystick-and-what-is-sdl-gamecontroller-what-are-the-relationships
+ case EventType::CONTROLLERBUTTONDOWN:
+ case EventType::CONTROLLERBUTTONUP:
- case EventType::CONTROLLERAXISMOTION:
+ case EventType::CONTROLLERAXISMOTION:
- default:
- // Ignore oter events and pop up the event table.
- luax_pop(L, 1);
- goto poll;
- break;
- }
- luax_rawseti(L, -2, i++);
- }
- return 1;
- }
+ default:
+ // Ignore oter events and pop up the event table.
+ luax_pop(L, 1);
+ goto poll;
+ break;
+ }
+ luax_rawseti(L, -2, i++);
+ }
+ return 1;
+ }
- /**
- * load event module
- */
- LUA_EXPORT int luaopen_event(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "poll", l_event_poll },
- { 0, 0 }
- };
- luax_newlib(L, methods);
+ /**
+ * load event module
+ */
+ LUA_EXPORT int luaopen_event(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "poll", l_event_poll },
+ { 0, 0 }
+ };
+ luax_newlib(L, methods);
- return 1;
- }
+ return 1;
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/event/l_event.h b/src/libjin-lua/modules/event/l_event.h
index 7a75459..1b593c8 100644
--- a/src/libjin-lua/modules/event/l_event.h
+++ b/src/libjin-lua/modules/event/l_event.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_event(lua_State* L);
+ int luaopen_event(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/filesystem/l_filesystem.h b/src/libjin-lua/modules/filesystem/l_filesystem.h
index 1e1ff23..b47b3c0 100644
--- a/src/libjin-lua/modules/filesystem/l_filesystem.h
+++ b/src/libjin-lua/modules/filesystem/l_filesystem.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_filesystem(lua_State* L);
+ int luaopen_filesystem(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_animation.cpp b/src/libjin-lua/modules/graphics/l_animation.cpp
index 0bf133f..9fb7590 100644
--- a/src/libjin-lua/modules/graphics/l_animation.cpp
+++ b/src/libjin-lua/modules/graphics/l_animation.cpp
@@ -16,107 +16,107 @@ using namespace JinEngine::Graphics::Animations;
namespace JinEngine
{
- namespace Lua
- {
- const char* Jin_Lua_Animation = "Animation";
+ namespace Lua
+ {
+ const char* Jin_Lua_Animation = "Animation";
- LUA_IMPLEMENT inline Animation* checkAnimation(lua_State* L)
- {
- LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_Animation);
- return luaObj->getObject<Animation>();
- }
+ LUA_IMPLEMENT inline Animation* checkAnimation(lua_State* L)
+ {
+ LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_Animation);
+ return luaObj->getObject<Animation>();
+ }
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
- p->release();
- return 0;
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
+ p->release();
+ return 0;
+ }
- // addFrame(frame)
- LUA_IMPLEMENT int l_addFrame(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
- Animation* animation = luaObj->getObject<Animation>();
- LuaObject* luaSprite = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Sprite);
- Sprite* sprite = luaSprite->getObject<Sprite>();
- animation->addFrame(sprite);
- int i = animation->getFrameCount() - 1;
- luaObj->setDependency((int)AnimationDependency::DEP_SPRITES + i, luaSprite);
- return 0;
- }
+ // addFrame(frame)
+ LUA_IMPLEMENT int l_addFrame(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
+ Animation* animation = luaObj->getObject<Animation>();
+ LuaObject* luaSprite = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Sprite);
+ Sprite* sprite = luaSprite->getObject<Sprite>();
+ animation->addFrame(sprite);
+ int i = animation->getFrameCount() - 1;
+ luaObj->setDependency((int)AnimationDependency::DEP_SPRITES + i, luaSprite);
+ return 0;
+ }
- // addFrames(frames table)
- LUA_IMPLEMENT int l_addFrames(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
- Animation* shrAnimation = luaObj->getObject<Animation>();
- if (!luax_istable(L, 2))
- {
- luax_typerror(L, 2, "sprites table");
- return 1;
- }
- int n = luax_tableidxlen(L, 2);
- for (int i = 1; i <= n; ++i)
- {
- luax_rawgeti(L, 2, i);
- LuaObject* luaSprite = (LuaObject*)luax_checktype(L, -1, Jin_Lua_Sprite);
- Sprite* sprite = luaSprite->getObject<Sprite>();
- shrAnimation->addFrame(sprite);
- int index = shrAnimation->getFrameCount() - 1;
- luaObj->setDependency((int)AnimationDependency::DEP_SPRITES + index, luaSprite);
- }
- return 0;
- }
+ // addFrames(frames table)
+ LUA_IMPLEMENT int l_addFrames(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
+ Animation* shrAnimation = luaObj->getObject<Animation>();
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "sprites table");
+ return 1;
+ }
+ int n = luax_tableidxlen(L, 2);
+ for (int i = 1; i <= n; ++i)
+ {
+ luax_rawgeti(L, 2, i);
+ LuaObject* luaSprite = (LuaObject*)luax_checktype(L, -1, Jin_Lua_Sprite);
+ Sprite* sprite = luaSprite->getObject<Sprite>();
+ shrAnimation->addFrame(sprite);
+ int index = shrAnimation->getFrameCount() - 1;
+ luaObj->setDependency((int)AnimationDependency::DEP_SPRITES + index, luaSprite);
+ }
+ return 0;
+ }
- LUA_IMPLEMENT int l_isLoop(lua_State* L)
- {
- Animation* shrAnimation = checkAnimation(L);
- bool loop = shrAnimation->isLoop();
- luax_pushboolean(L, loop);
- return 1;
- }
+ LUA_IMPLEMENT int l_isLoop(lua_State* L)
+ {
+ Animation* shrAnimation = checkAnimation(L);
+ bool loop = shrAnimation->isLoop();
+ luax_pushboolean(L, loop);
+ return 1;
+ }
- LUA_IMPLEMENT int l_getSpeed(lua_State* L)
- {
- Animation* shrAnimation = checkAnimation(L);
- float speed = shrAnimation->getSpeed();
- luax_pushnumber(L, speed);
- return 1;
- }
+ LUA_IMPLEMENT int l_getSpeed(lua_State* L)
+ {
+ Animation* shrAnimation = checkAnimation(L);
+ float speed = shrAnimation->getSpeed();
+ luax_pushnumber(L, speed);
+ return 1;
+ }
- LUA_IMPLEMENT int l_getFrame(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
- Animation* shrAnimation = luaObj->getObject<Animation>();
- int i = luax_checkinteger(L, 2);
- LuaObject* frame = luaObj->getDependency((int)AnimationDependency::DEP_SPRITES + i);
- luax_getobject(L, frame);
- return 1;
- }
+ LUA_IMPLEMENT int l_getFrame(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
+ Animation* shrAnimation = luaObj->getObject<Animation>();
+ int i = luax_checkinteger(L, 2);
+ LuaObject* frame = luaObj->getDependency((int)AnimationDependency::DEP_SPRITES + i);
+ luax_getobject(L, frame);
+ return 1;
+ }
- LUA_IMPLEMENT int getFrameCount(lua_State* L)
- {
- Animation* shrAnimation = checkAnimation(L);
- int n = shrAnimation->getFrameCount();
- luax_pushinteger(L, n);
- return 1;
- }
+ LUA_IMPLEMENT int getFrameCount(lua_State* L)
+ {
+ Animation* shrAnimation = checkAnimation(L);
+ int n = shrAnimation->getFrameCount();
+ luax_pushinteger(L, n);
+ return 1;
+ }
- LUA_EXPORT void luaopen_Animation(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "addFrame", l_addFrame },
- { "addFrames", l_addFrames },
- { "isLoop", l_isLoop },
- { "getSpeed", l_getSpeed },
- { "getFrameCount", getFrameCount },
- { "getFrame", l_getFrame },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_Animation, methods);
- }
+ LUA_EXPORT void luaopen_Animation(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "addFrame", l_addFrame },
+ { "addFrames", l_addFrames },
+ { "isLoop", l_isLoop },
+ { "getSpeed", l_getSpeed },
+ { "getFrameCount", getFrameCount },
+ { "getFrame", l_getFrame },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Animation, methods);
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_animation.h b/src/libjin-lua/modules/graphics/l_animation.h
index 1b32ec3..eb308a8 100644
--- a/src/libjin-lua/modules/graphics/l_animation.h
+++ b/src/libjin-lua/modules/graphics/l_animation.h
@@ -3,22 +3,22 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_Animation;
+ extern const char* Jin_Lua_Animation;
- ///
- ///
- ///
- enum class AnimationDependency
- {
- DEP_SPRITES = 1 ///< Index from 1
- };
+ ///
+ ///
+ ///
+ enum class AnimationDependency
+ {
+ DEP_SPRITES = 1 ///< Index from 1
+ };
- void luaopen_Animation(lua_State* L);
+ void luaopen_Animation(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_animator.cpp b/src/libjin-lua/modules/graphics/l_animator.cpp
index 7927ca4..404fa26 100644
--- a/src/libjin-lua/modules/graphics/l_animator.cpp
+++ b/src/libjin-lua/modules/graphics/l_animator.cpp
@@ -16,148 +16,148 @@ using namespace JinEngine::Graphics::Animations;
namespace JinEngine
{
- namespace Lua
- {
- const char* Jin_Lua_Animator = "Animator";
-
- LUA_IMPLEMENT inline Animator* checkAnimator(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animator);
- return luaObj->getObject<Animator>();
- }
-
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* obj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
- obj->release();
- return 0;
- }
-
- LUA_IMPLEMENT int l_update(lua_State* L)
- {
- Animator* animator = checkAnimator(L);
- float dt = luax_checknumber(L, 2);
- animator->update(dt);
- return 0;
- }
-
- LUA_IMPLEMENT int l_play(lua_State* L)
- {
- Animator* animator = checkAnimator(L);
- animator->play();
- return 0;
- }
-
- LUA_IMPLEMENT int l_pause(lua_State* L)
- {
- Animator* animator = checkAnimator(L);
- animator->pause();
- return 0;
- }
-
- LUA_IMPLEMENT int l_resume(lua_State* L)
- {
- Animator* animator = checkAnimator(L);
- animator->resume();
- return 0;
- }
-
- LUA_IMPLEMENT int l_rewind(lua_State* L)
- {
- Animator* animator = checkAnimator(L);
- animator->rewind();
- return 0;
- }
-
- LUA_IMPLEMENT int l_render(lua_State* L)
- {
- Animator* animator = checkAnimator(L);
- float x = luax_checknumber(L, 2);
- float y = luax_checknumber(L, 3);
- float sx = luax_checknumber(L, 4);
- float sy = luax_checknumber(L, 5);
- float r = luax_checknumber(L, 6);
- animator->render(x, y, sx, sy, r);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setAnimation(lua_State* L)
- {
- LuaObject* luaAnimator = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animator);
- Animator* animator = luaAnimator->getObject<Animator>();
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
- luaAnimator->setDependency((int)AnimatorDependency::DEP_ANIMATION, luaObj);
- animator->setAnimation(luaObj->getObject<Animation>());
- return 0;
- }
-
- LUA_IMPLEMENT int l_forceToFrame(lua_State* L)
- {
- Animator* shrAnimator = checkAnimator(L);
- int index = luax_checkinteger(L, 2);
- shrAnimator->forceToFrame(index);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setSpeed(lua_State* L)
- {
- Animator* shrAnimator = checkAnimator(L);
- float fps = luax_checknumber(L, 2);
- shrAnimator->setSpeed(fps);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setDefaultSpeed(lua_State* L)
- {
- Animator* shrAnimator = checkAnimator(L);
- shrAnimator->setDefaultSpeed();
- return 0;
- }
-
- LUA_IMPLEMENT int l_setLoop(lua_State* L)
- {
- Animator* shrAnimator = checkAnimator(L);
- bool loop = luax_checkbool(L, 2);
- shrAnimator->setLoop(loop);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setDefaultLoop(lua_State* L)
- {
- Animator* shrAnimator = checkAnimator(L);
- shrAnimator->setDefaultLoop();
- return 0;
- }
-
- LUA_IMPLEMENT int l_getSpeed(lua_State* L)
- {
- Animator* shrAnimator = checkAnimator(L);
- float speed = shrAnimator->getSpeed();
- luax_pushnumber(L, speed);
- return 1;
- }
-
- LUA_EXPORT void luaopen_Animator(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "update", l_update },
- { "play", l_play },
- { "pause", l_pause },
- { "resume", l_resume },
- { "rewind", l_rewind },
- { "render", l_render },
- { "setAnimation", l_setAnimation },
- { "forceToFrame", l_forceToFrame },
- { "setSpeed", l_setSpeed },
- { "setDefaultSpeed", l_setDefaultSpeed },
- { "setLoop", l_setLoop },
- { "setDefaultLoop", l_setDefaultLoop },
- { "getSpeed", l_getSpeed },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_Animator, methods);
- }
-
- } // namespace Lua
+ namespace Lua
+ {
+ const char* Jin_Lua_Animator = "Animator";
+
+ LUA_IMPLEMENT inline Animator* checkAnimator(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animator);
+ return luaObj->getObject<Animator>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* obj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
+ obj->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_update(lua_State* L)
+ {
+ Animator* animator = checkAnimator(L);
+ float dt = luax_checknumber(L, 2);
+ animator->update(dt);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_play(lua_State* L)
+ {
+ Animator* animator = checkAnimator(L);
+ animator->play();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ Animator* animator = checkAnimator(L);
+ animator->pause();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_resume(lua_State* L)
+ {
+ Animator* animator = checkAnimator(L);
+ animator->resume();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rewind(lua_State* L)
+ {
+ Animator* animator = checkAnimator(L);
+ animator->rewind();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_render(lua_State* L)
+ {
+ Animator* animator = checkAnimator(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ float sx = luax_checknumber(L, 4);
+ float sy = luax_checknumber(L, 5);
+ float r = luax_checknumber(L, 6);
+ animator->render(x, y, sx, sy, r);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setAnimation(lua_State* L)
+ {
+ LuaObject* luaAnimator = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animator);
+ Animator* animator = luaAnimator->getObject<Animator>();
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Animation);
+ luaAnimator->setDependency((int)AnimatorDependency::DEP_ANIMATION, luaObj);
+ animator->setAnimation(luaObj->getObject<Animation>());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_forceToFrame(lua_State* L)
+ {
+ Animator* shrAnimator = checkAnimator(L);
+ int index = luax_checkinteger(L, 2);
+ shrAnimator->forceToFrame(index);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setSpeed(lua_State* L)
+ {
+ Animator* shrAnimator = checkAnimator(L);
+ float fps = luax_checknumber(L, 2);
+ shrAnimator->setSpeed(fps);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setDefaultSpeed(lua_State* L)
+ {
+ Animator* shrAnimator = checkAnimator(L);
+ shrAnimator->setDefaultSpeed();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setLoop(lua_State* L)
+ {
+ Animator* shrAnimator = checkAnimator(L);
+ bool loop = luax_checkbool(L, 2);
+ shrAnimator->setLoop(loop);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setDefaultLoop(lua_State* L)
+ {
+ Animator* shrAnimator = checkAnimator(L);
+ shrAnimator->setDefaultLoop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getSpeed(lua_State* L)
+ {
+ Animator* shrAnimator = checkAnimator(L);
+ float speed = shrAnimator->getSpeed();
+ luax_pushnumber(L, speed);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_Animator(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "update", l_update },
+ { "play", l_play },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "rewind", l_rewind },
+ { "render", l_render },
+ { "setAnimation", l_setAnimation },
+ { "forceToFrame", l_forceToFrame },
+ { "setSpeed", l_setSpeed },
+ { "setDefaultSpeed", l_setDefaultSpeed },
+ { "setLoop", l_setLoop },
+ { "setDefaultLoop", l_setDefaultLoop },
+ { "getSpeed", l_getSpeed },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Animator, methods);
+ }
+
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_animator.h b/src/libjin-lua/modules/graphics/l_animator.h
index 0292a77..0fdd78c 100644
--- a/src/libjin-lua/modules/graphics/l_animator.h
+++ b/src/libjin-lua/modules/graphics/l_animator.h
@@ -5,19 +5,19 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_Animator;
+ extern const char* Jin_Lua_Animator;
- enum class AnimatorDependency
- {
- DEP_ANIMATION = 1
- };
+ enum class AnimatorDependency
+ {
+ DEP_ANIMATION = 1
+ };
- void luaopen_Animator(lua_State* L);
+ void luaopen_Animator(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_bitmap.cpp b/src/libjin-lua/modules/graphics/l_bitmap.cpp
index c081cef..6b4bbce 100644
--- a/src/libjin-lua/modules/graphics/l_bitmap.cpp
+++ b/src/libjin-lua/modules/graphics/l_bitmap.cpp
@@ -8,103 +8,103 @@ using namespace JinEngine::Graphics;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- const char* Jin_Lua_Bitmap = "Bitmap";
+ const char* Jin_Lua_Bitmap = "Bitmap";
- LUA_IMPLEMENT inline Bitmap* checkBitmap(lua_State* L)
- {
- LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_Bitmap);
- return luaObj->getObject<Bitmap>();
- }
+ LUA_IMPLEMENT inline Bitmap* checkBitmap(lua_State* L)
+ {
+ LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_Bitmap);
+ return luaObj->getObject<Bitmap>();
+ }
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Bitmap);
- luaObj->release();
- return 0;
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Bitmap);
+ luaObj->release();
+ return 0;
+ }
- LUA_IMPLEMENT int l_getWidth(lua_State* L)
- {
- Bitmap* bitmap = checkBitmap(L);
- int w = bitmap->getWidth();
- luax_pushinteger(L, w);
- return 1;
- }
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ Bitmap* bitmap = checkBitmap(L);
+ int w = bitmap->getWidth();
+ luax_pushinteger(L, w);
+ return 1;
+ }
- LUA_IMPLEMENT int l_getHeight(lua_State* L)
- {
- Bitmap* bitmap = checkBitmap(L);
- int h = bitmap->getHeight();
- luax_pushinteger(L, h);
- return 1;
- }
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
+ {
+ Bitmap* bitmap = checkBitmap(L);
+ int h = bitmap->getHeight();
+ luax_pushinteger(L, h);
+ return 1;
+ }
- LUA_IMPLEMENT int l_getSize(lua_State* L)
- {
- Bitmap* bitmap = checkBitmap(L);
- int w = bitmap->getWidth();
- int h = bitmap->getHeight();
- luax_pushinteger(L, w);
- luax_pushinteger(L, h);
- return 2;
- }
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ Bitmap* bitmap = checkBitmap(L);
+ int w = bitmap->getWidth();
+ int h = bitmap->getHeight();
+ luax_pushinteger(L, w);
+ luax_pushinteger(L, h);
+ return 2;
+ }
- LUA_IMPLEMENT int l_getPixel(lua_State* L)
- {
- Bitmap* bitmap = checkBitmap(L);
- int x = luax_checkinteger(L, 2);
- int y = luax_checkinteger(L, 3);
- Color col = bitmap->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_getPixel(lua_State* L)
+ {
+ Bitmap* bitmap = checkBitmap(L);
+ int x = luax_checkinteger(L, 2);
+ int y = luax_checkinteger(L, 3);
+ Color col = bitmap->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)
- {
- Bitmap* bitmap = 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);
- bitmap->setPixel(Color(r, g, b, a), x, y);
- return 0;
- }
+ LUA_IMPLEMENT int l_setPixel(lua_State* L)
+ {
+ Bitmap* bitmap = 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);
+ bitmap->setPixel(Color(r, g, b, a), x, y);
+ return 0;
+ }
- LUA_IMPLEMENT int l_clone(lua_State* L)
- {
- Bitmap* bitmap = checkBitmap(L);
- Bitmap* b = bitmap->clone();
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Bitmap, new Shared(b));
- return 1;
- }
-
- LUA_EXPORT void luaopen_Bitmap(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__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, methods);
- }
+ LUA_IMPLEMENT int l_clone(lua_State* L)
+ {
+ Bitmap* bitmap = checkBitmap(L);
+ Bitmap* b = bitmap->clone();
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Bitmap, new Shared(b));
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_Bitmap(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__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, methods);
+ }
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_bitmap.h b/src/libjin-lua/modules/graphics/l_bitmap.h
index b463d83..51a69f1 100644
--- a/src/libjin-lua/modules/graphics/l_bitmap.h
+++ b/src/libjin-lua/modules/graphics/l_bitmap.h
@@ -3,14 +3,14 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_Bitmap;
+ extern const char* Jin_Lua_Bitmap;
- void luaopen_Bitmap(lua_State* L);
+ void luaopen_Bitmap(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_canvas.cpp b/src/libjin-lua/modules/graphics/l_canvas.cpp
index 3979085..87737e9 100644
--- a/src/libjin-lua/modules/graphics/l_canvas.cpp
+++ b/src/libjin-lua/modules/graphics/l_canvas.cpp
@@ -7,57 +7,57 @@ using namespace JinEngine::Graphics;
namespace JinEngine
{
- namespace Lua
- {
-
- const char* Jin_Lua_Canvas = "Canvas";
-
- LUA_IMPLEMENT inline Canvas* checkCanvas(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Canvas);
- return luaObj->getObject<Canvas>();
- }
-
- LUA_IMPLEMENT int l_getWidth(lua_State* L)
- {
- Canvas* canvas = checkCanvas(L);
- luax_pushnumber(L, canvas->getWidth());
- return 1;
- }
-
- LUA_IMPLEMENT int l_getHeight(lua_State* L)
- {
- Canvas* canvas = checkCanvas(L);
- luax_pushnumber(L, canvas->getHeight());
- return 1;
- }
-
- LUA_IMPLEMENT int l_getSize(lua_State* L)
- {
- Canvas* canvas = checkCanvas(L);
- luax_pushnumber(L, canvas->getWidth());
- luax_pushnumber(L, canvas->getHeight());
- return 2;
- }
-
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Canvas);
- luaObj->release();
- return 0;
- }
-
- LUA_EXPORT void luaopen_Canvas(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_Canvas, methods);
- }
-
- } // namespace Lua
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Canvas = "Canvas";
+
+ LUA_IMPLEMENT inline Canvas* checkCanvas(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ return luaObj->getObject<Canvas>();
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ Canvas* canvas = checkCanvas(L);
+ luax_pushnumber(L, canvas->getWidth());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
+ {
+ Canvas* canvas = checkCanvas(L);
+ luax_pushnumber(L, canvas->getHeight());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ Canvas* canvas = checkCanvas(L);
+ luax_pushnumber(L, canvas->getWidth());
+ luax_pushnumber(L, canvas->getHeight());
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ luaObj->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Canvas(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Canvas, methods);
+ }
+
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_canvas.h b/src/libjin-lua/modules/graphics/l_canvas.h
index d1fa885..80f5329 100644
--- a/src/libjin-lua/modules/graphics/l_canvas.h
+++ b/src/libjin-lua/modules/graphics/l_canvas.h
@@ -3,14 +3,14 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_Canvas;
+ extern const char* Jin_Lua_Canvas;
- void luaopen_Canvas(lua_State* L);
+ void luaopen_Canvas(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_graphics.h b/src/libjin-lua/modules/graphics/l_graphics.h
index 02a2c63..7bfb84b 100644
--- a/src/libjin-lua/modules/graphics/l_graphics.h
+++ b/src/libjin-lua/modules/graphics/l_graphics.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_graphics(lua_State* L);
+ int luaopen_graphics(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_mesh.cpp b/src/libjin-lua/modules/graphics/l_mesh.cpp
index 73e0024..8e7581c 100644
--- a/src/libjin-lua/modules/graphics/l_mesh.cpp
+++ b/src/libjin-lua/modules/graphics/l_mesh.cpp
@@ -9,79 +9,79 @@ using namespace JinEngine::Graphics;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- const char* Jin_Lua_Mesh = "Mesh";
+ const char* Jin_Lua_Mesh = "Mesh";
- LUA_IMPLEMENT inline Mesh* checkMesh(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Mesh);
- return luaObj->getObject<Mesh>();
- }
+ LUA_IMPLEMENT inline Mesh* checkMesh(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Mesh);
+ return luaObj->getObject<Mesh>();
+ }
- LUA_IMPLEMENT int l_getBound(lua_State* L)
- {
- Mesh* mesh = checkMesh(L);
- BBox bbox = mesh->getBound();
- luax_pushnumber(L, bbox.l);
- luax_pushnumber(L, bbox.r);
- luax_pushnumber(L, bbox.t);
- luax_pushnumber(L, bbox.b);
- return 4;
- }
+ LUA_IMPLEMENT int l_getBound(lua_State* L)
+ {
+ Mesh* mesh = checkMesh(L);
+ BBox bbox = mesh->getBound();
+ luax_pushnumber(L, bbox.l);
+ luax_pushnumber(L, bbox.r);
+ luax_pushnumber(L, bbox.t);
+ luax_pushnumber(L, bbox.b);
+ return 4;
+ }
- LUA_IMPLEMENT int l_setGraphic(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Mesh);
- Mesh* mesh = luaObj->getObject<Mesh>();
- luaObj->removeDependency((int)MeshDependency::DEP_GRAPHIC);
- LuaObject* obj = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Texture);
- mesh->setGraphic(obj->getObject<Texture>());
- luaObj->setDependency((int)MeshDependency::DEP_GRAPHIC, obj);
- return 0;
- }
+ LUA_IMPLEMENT int l_setGraphic(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Mesh);
+ Mesh* mesh = luaObj->getObject<Mesh>();
+ luaObj->removeDependency((int)MeshDependency::DEP_GRAPHIC);
+ LuaObject* obj = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Texture);
+ mesh->setGraphic(obj->getObject<Texture>());
+ luaObj->setDependency((int)MeshDependency::DEP_GRAPHIC, obj);
+ return 0;
+ }
- // x, y, u, v, color_table
- LUA_IMPLEMENT int l_pushVertex(lua_State* L)
- {
- Mesh* mesh = checkMesh(L);
- float x = luax_checknumber(L, 2);
- float y = luax_checknumber(L, 3);
- float u = luax_checknumber(L, 4);
- float v = luax_checknumber(L, 5);
- if (!luax_istable(L, 6))
- {
- luax_typerror(L, 6, "color table");
- return 1;
- }
- 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);
- mesh->pushVertex(x, y, u, v, c);
- return 0;
- }
+ // x, y, u, v, color_table
+ LUA_IMPLEMENT int l_pushVertex(lua_State* L)
+ {
+ Mesh* mesh = checkMesh(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ float u = luax_checknumber(L, 4);
+ float v = luax_checknumber(L, 5);
+ if (!luax_istable(L, 6))
+ {
+ luax_typerror(L, 6, "color table");
+ return 1;
+ }
+ 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);
+ mesh->pushVertex(x, y, u, v, c);
+ return 0;
+ }
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Mesh);
- luaObj->release();
- return 0;
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Mesh);
+ luaObj->release();
+ return 0;
+ }
- LUA_EXPORT void luaopen_Mesh(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "getBound", l_getBound },
- { "setGraphic", l_setGraphic },
- { "pushVertex", l_pushVertex },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_Mesh, methods);
- }
+ LUA_EXPORT void luaopen_Mesh(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "getBound", l_getBound },
+ { "setGraphic", l_setGraphic },
+ { "pushVertex", l_pushVertex },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Mesh, methods);
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_mesh.h b/src/libjin-lua/modules/graphics/l_mesh.h
index b3fa00e..25ad108 100644
--- a/src/libjin-lua/modules/graphics/l_mesh.h
+++ b/src/libjin-lua/modules/graphics/l_mesh.h
@@ -3,19 +3,19 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- enum class MeshDependency
- {
- DEP_GRAPHIC = 1,
- };
+ enum class MeshDependency
+ {
+ DEP_GRAPHIC = 1,
+ };
- extern const char* Jin_Lua_Mesh;
+ extern const char* Jin_Lua_Mesh;
- void luaopen_Mesh(lua_State* L);
+ void luaopen_Mesh(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_page.cpp b/src/libjin-lua/modules/graphics/l_page.cpp
index b7aeb95..1b3f05d 100644
--- a/src/libjin-lua/modules/graphics/l_page.cpp
+++ b/src/libjin-lua/modules/graphics/l_page.cpp
@@ -10,57 +10,57 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- const char* Jin_Lua_Page = "Page";
+ const char* Jin_Lua_Page = "Page";
- Page* getPage(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Page);
- return luaObj->getObject<Page>();
- }
+ Page* getPage(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Page);
+ return luaObj->getObject<Page>();
+ }
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Page);
- luaObj->release();
- return 0;
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Page);
+ luaObj->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_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_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_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 methods[] = {
- { "__gc", l_gc },
- { "getSize", l_getSize },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_Page, methods);
- }
+ LUA_EXPORT void luaopen_Page(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "getSize", l_getSize },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Page, methods);
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_page.h b/src/libjin-lua/modules/graphics/l_page.h
index e4a21a3..c781e66 100644
--- a/src/libjin-lua/modules/graphics/l_page.h
+++ b/src/libjin-lua/modules/graphics/l_page.h
@@ -3,20 +3,20 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- enum class PageDependency
- {
- DEP_TTF = 1,
- DEP_TEXTURE_FONT = 2,
- };
+ enum class PageDependency
+ {
+ DEP_TTF = 1,
+ DEP_TEXTURE_FONT = 2,
+ };
- extern const char* Jin_Lua_Page;
+ extern const char* Jin_Lua_Page;
- void luaopen_Page(lua_State* L);
+ void luaopen_Page(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_particle_system.cpp b/src/libjin-lua/modules/graphics/l_particle_system.cpp
index 5830221..8847552 100644
--- a/src/libjin-lua/modules/graphics/l_particle_system.cpp
+++ b/src/libjin-lua/modules/graphics/l_particle_system.cpp
@@ -14,409 +14,409 @@ using namespace JinEngine::Graphics::Particles;
namespace JinEngine
{
- namespace Lua
- {
-
- const char* Jin_Lua_ParticleSystem = "ParticleSystem";
-
- LUA_IMPLEMENT inline ParticleSystem* checkPS(lua_State* L)
- {
- LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
- return luaObj->getObject<ParticleSystem>();
- }
-
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
- luaObj->release();
- return 0;
- }
-
- LUA_IMPLEMENT int l_update(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- float dt = luax_checknumber(L, 2);
- ps->update(dt);
- return 0;
- }
-
- LUA_IMPLEMENT int l_render(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- ps->render();
- return 0;
- }
-
- LUA_IMPLEMENT int l_setPosition(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- float x = luax_checknumber(L, 2);
- float y = luax_checknumber(L, 3);
- ps->setPosition(x, y);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setScale(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- float sx = luax_checknumber(L, 2);
- float sy = luax_checknumber(L, 3);
- //ps->setScale(sx, sy);
- return 0;
- }
-
- LUA_IMPLEMENT int l_pause(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- bool b = luax_checkbool(L, 2);
- //ps->pause(b);
- return 0;
- }
-
- LUA_IMPLEMENT int l_clear(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- //ps->clear();
- return 0;
- }
-
- LUA_IMPLEMENT int l_setEmitRate(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- if (luax_gettop(L) >= 3)
- {
- float floor = luax_checknumber(L, 2);
- float ceil = luax_checknumber(L, 3);
- ps->setEmitRate(floor, ceil);
- }
- else if (luax_gettop(L) >= 2)
- {
- float n = luax_checknumber(L, 2);
- ps->setEmitRate(n);
- }
- return 0;
- }
-
- LUA_IMPLEMENT int l_setEmitForce(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- if (luax_gettop(L) >= 3)
- {
- float floor = luax_checknumber(L, 2);
- float ceil = luax_checknumber(L, 3);
- ps->setEmitForce(floor, ceil);
- }
- else if (luax_gettop(L) >= 2)
- {
- float n = luax_checknumber(L, 2);
- ps->setEmitForce(n);
- }
- return 0;
- }
-
- LUA_IMPLEMENT int l_setEmitDirection(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- if (luax_gettop(L) >= 3)
- {
- float floor = luax_checknumber(L, 2);
- float ceil = luax_checknumber(L, 3);
- ps->setEmitDirection(floor, ceil);
- }
- else if (luax_gettop(L) >= 2)
- {
- float n = luax_checknumber(L, 2);
- ps->setEmitDirection(n);
- }
- return 0;
- }
-
- LUA_IMPLEMENT int l_setEmitPosition(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- if (luax_gettop(L) >= 3)
- {
- if (!luax_istable(L, 2))
- {
- luax_typerror(L, 2, "table");
- return 1;
- }
- if (!luax_istable(L, 3))
- {
- luax_typerror(L, 3, "table");
- return 1;
- }
- Vector2<float> floor, ceil;
- floor.x() = luax_rawgetnumber(L, 2, 1);
- floor.y() = luax_rawgetnumber(L, 2, 2);
- ceil.x() = luax_rawgetnumber(L, 3, 1);
- ceil.y() = luax_rawgetnumber(L, 3, 2);
- ps->setEmitPosition(floor, ceil);
- }
- else if (luax_gettop(L) >= 2)
- {
- if (!luax_istable(L, 2))
- {
- luax_typerror(L, 2, "table");
- return 1;
- }
- Vector2<float> pos;
- pos.x() = luax_rawgetnumber(L, 2, 1);
- pos.y() = luax_rawgetnumber(L, 2, 2);
- ps->setEmitPosition(pos);
- }
- return 0;
- }
-
- LUA_IMPLEMENT int l_setParticleLife(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- if (luax_gettop(L) >= 3)
- {
- float floor = luax_checknumber(L, 2);
- float ceil = luax_checknumber(L, 3);
- ps->setParticleLife(floor, ceil);
- }
- else if (luax_gettop(L) >= 2)
- {
- float n = luax_checknumber(L, 2);
- ps->setParticleLife(n);
- }
- return 0;
- }
-
- LUA_IMPLEMENT int l_setParticleLinearAccelaration(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- if (!luax_istable(L, 2))
- {
- luax_typerror(L, 2, "table");
- return 1;
- }
- Vector2<float> ac;
- ac.x() = luax_rawgetnumber(L, 2, 1);
- ac.y() = luax_rawgetnumber(L, 2, 2);
- ps->setParticleLinearAccelaration(ac);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setParticleRadialAccelaration(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- float ra = luax_checknumber(L, 2);
- ps->setParticleRadialAccelaration(ra);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setParticleAngularSpeed(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- if (luax_gettop(L) >= 3)
- {
- float floor = luax_checknumber(L, 2);
- float ceil = luax_checknumber(L, 3);
- ps->setParticleAngularSpeed(floor, ceil);
- }
- else if (luax_gettop(L) >= 2)
- {
- float n = luax_checknumber(L, 2);
- ps->setParticleAngularSpeed(n);
- }
- return 0;
- }
-
- LUA_IMPLEMENT int l_setParticleSpritesMode(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- int n = luax_checkinteger(L, 2);
- SpriteMode mode = static_cast<SpriteMode>(n);
- ps->setParticleSpritesMode(mode);
- return 0;
- }
-
- LUA_IMPLEMENT int l_addParticleSprite(lua_State* L)
- {
- LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
- ParticleSystem* ps = obj->getObject<ParticleSystem>();
- LuaObject* objSpr = luax_checkobject(L, 2, Jin_Lua_Sprite);
- Sprite* spr = objSpr->getObject<Sprite>();
- ps->addParticleSprite(spr);
- int depn = (*obj).getDependenciesCount();
- (*obj).setDependency((int)ParticleSystemDependency::DEP_SPRITES + depn, objSpr);
- return 0;
- }
-
- LUA_IMPLEMENT int l_addParticleSprites(lua_State* L)
- {
- LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
- ParticleSystem* ps = obj->getObject<ParticleSystem>();
- if (!luax_istable(L, 2))
- {
- luax_typerror(L, 2, "sprites table");
- return 1;
- }
- int n = luax_tableidxlen(L, 2);
- int depn = (*obj).getDependenciesCount();
- for (int i = 1; i <= n; ++i)
- {
- luax_rawgeti(L, 2, i);
- LuaObject* objSpr = luax_checkobject(L, -1, Jin_Lua_Sprite);
- luax_pop(L, 1);
- Sprite* spr = objSpr->getObject<Sprite>();
- ps->addParticleSprite(spr);
- (*obj).setDependency((int)ParticleSystemDependency::DEP_SPRITES + depn + i - 1, objSpr);
- }
- return 0;
- }
-
- // From 0
- LUA_IMPLEMENT int l_removeParticleSprite(lua_State* L)
- {
- LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
- ParticleSystem* ps = obj->getObject<ParticleSystem>();
- int n = luax_checkinteger(L, 2);
- ps->removeParticleSprite(n);
- (*obj).removeDependency((int)ParticleSystemDependency::DEP_SPRITES + n);
- return 0;
- }
-
- LUA_IMPLEMENT int l_enableParticleBlendAdditive(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- bool enable = luax_checkbool(L, 2);
- ps->enableParticleBlendAdditive(enable);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setParticleScale(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- float scale = luax_checknumber(L, 2);
- ps->setParticleScale(scale);
- return 0;
- }
-
- LUA_IMPLEMENT int l_addParticleScalePoint(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- float scale = luax_checknumber(L, 2);
- float t = luax_checknumber(L, 3);
- ps->addParticleScalePoint(scale, t);
- return 0;
- }
-
- LUA_IMPLEMENT int l_removeParticleScalePoint(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- int i = luax_checkinteger(L, 2);
- ps->removeParticleScalePoint(i);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setParticleColor(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- if (!luax_istable(L, 2))
- {
- luax_typerror(L, 2, "color table");
- return 1;
- }
- Color c;
- c.r = luax_rawgetnumber(L, 2, 1);
- c.g = luax_rawgetnumber(L, 2, 2);
- c.b = luax_rawgetnumber(L, 2, 3);
- c.a = luax_rawgetnumber(L, 2, 4);
- ps->setParticleColor(c);
- return 0;
- }
-
- LUA_IMPLEMENT int l_addParticleColorPoint(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- if (!luax_istable(L, 2))
- {
- luax_typerror(L, 2, "color table");
- return 1;
- }
- Color c;
- c.r = luax_rawgetnumber(L, 2, 1);
- c.g = luax_rawgetnumber(L, 2, 2);
- c.b = luax_rawgetnumber(L, 2, 3);
- c.a = luax_rawgetnumber(L, 2, 4);
- float t = luax_checknumber(L, 3);
- ps->addParticleColorPoint(c, t);
- return 0;
- }
-
- LUA_IMPLEMENT int l_removeParticleColorPoint(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- int i = luax_checkinteger(L, 2);
- ps->removeParticleColorPoint(i);
- return 0;
- }
-
- LUA_IMPLEMENT int l_setParticleTransparency(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- float transparency = luax_checknumber(L, 2);
- ps->setParticleTransparency(transparency);
- return 0;
- }
-
- LUA_IMPLEMENT int l_addParticleTransparencyPoint(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- float transparency = luax_checknumber(L, 2);
- float t = luax_checknumber(L, 3);
- ps->addParticleTransparencyPoint(transparency, t);
- return 0;
- }
-
- LUA_IMPLEMENT int l_removeParticleTransparencyPoint(lua_State* L)
- {
- ParticleSystem* ps = checkPS(L);
- int i = luax_checkinteger(L, 2);
- ps->removeParticleTransparencyPoint(i);
- return 0;
- }
-
- LUA_EXPORT void luaopen_ParticleSystem(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "update", l_update },
- { "render", l_render },
- { "setPosition", l_setPosition },
- { "setScale", l_setScale },
- { "pause", l_pause },
- { "clear", l_clear },
- { "setEmitRate", l_setEmitRate },
- { "setEmitForce", l_setEmitForce },
- { "setEmitDirection", l_setEmitDirection },
- { "setEmitPosition", l_setEmitPosition },
- { "setParticleLife", l_setParticleLife },
- { "setParticleLinearAccelaration", l_setParticleLinearAccelaration },
- { "setParticleRadialAccelaration", l_setParticleRadialAccelaration },
- { "setParticleAngularSpeed", l_setParticleAngularSpeed },
- { "setParticleSpritesMode", l_setParticleSpritesMode },
- { "addParticleSprite", l_addParticleSprite },
- { "addParticleSprites", l_addParticleSprites },
- { "removeParticleSprite", l_removeParticleSprite },
- { "enableParticleBlendAdditive", l_enableParticleBlendAdditive },
- { "setParticleScale", l_setParticleScale },
- { "addParticleScalePoint", l_addParticleScalePoint },
- { "removeParticleScalePoint", l_removeParticleScalePoint },
- { "setParticleColor", l_setParticleColor },
- { "addParticleColorPoint", l_addParticleColorPoint },
- { "removeParticleColorPoint", l_removeParticleColorPoint },
- { "setParticleTransparency", l_setParticleTransparency },
- { "addParticleTransparencyPoint", l_addParticleTransparencyPoint },
- { "removeParticleTransparencyPoint", l_removeParticleTransparencyPoint },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_ParticleSystem, methods);
- }
-
- } // namespace Lua
+ namespace Lua
+ {
+
+ const char* Jin_Lua_ParticleSystem = "ParticleSystem";
+
+ LUA_IMPLEMENT inline ParticleSystem* checkPS(lua_State* L)
+ {
+ LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
+ return luaObj->getObject<ParticleSystem>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
+ luaObj->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_update(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ float dt = luax_checknumber(L, 2);
+ ps->update(dt);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_render(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ ps->render();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setPosition(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ ps->setPosition(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setScale(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ float sx = luax_checknumber(L, 2);
+ float sy = luax_checknumber(L, 3);
+ //ps->setScale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ bool b = luax_checkbool(L, 2);
+ //ps->pause(b);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_clear(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ //ps->clear();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setEmitRate(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ float floor = luax_checknumber(L, 2);
+ float ceil = luax_checknumber(L, 3);
+ ps->setEmitRate(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ float n = luax_checknumber(L, 2);
+ ps->setEmitRate(n);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setEmitForce(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ float floor = luax_checknumber(L, 2);
+ float ceil = luax_checknumber(L, 3);
+ ps->setEmitForce(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ float n = luax_checknumber(L, 2);
+ ps->setEmitForce(n);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setEmitDirection(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ float floor = luax_checknumber(L, 2);
+ float ceil = luax_checknumber(L, 3);
+ ps->setEmitDirection(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ float n = luax_checknumber(L, 2);
+ ps->setEmitDirection(n);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setEmitPosition(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "table");
+ return 1;
+ }
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ Vector2<float> floor, ceil;
+ floor.x() = luax_rawgetnumber(L, 2, 1);
+ floor.y() = luax_rawgetnumber(L, 2, 2);
+ ceil.x() = luax_rawgetnumber(L, 3, 1);
+ ceil.y() = luax_rawgetnumber(L, 3, 2);
+ ps->setEmitPosition(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "table");
+ return 1;
+ }
+ Vector2<float> pos;
+ pos.x() = luax_rawgetnumber(L, 2, 1);
+ pos.y() = luax_rawgetnumber(L, 2, 2);
+ ps->setEmitPosition(pos);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleLife(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ float floor = luax_checknumber(L, 2);
+ float ceil = luax_checknumber(L, 3);
+ ps->setParticleLife(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ float n = luax_checknumber(L, 2);
+ ps->setParticleLife(n);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleLinearAccelaration(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "table");
+ return 1;
+ }
+ Vector2<float> ac;
+ ac.x() = luax_rawgetnumber(L, 2, 1);
+ ac.y() = luax_rawgetnumber(L, 2, 2);
+ ps->setParticleLinearAccelaration(ac);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleRadialAccelaration(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ float ra = luax_checknumber(L, 2);
+ ps->setParticleRadialAccelaration(ra);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleAngularSpeed(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ float floor = luax_checknumber(L, 2);
+ float ceil = luax_checknumber(L, 3);
+ ps->setParticleAngularSpeed(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ float n = luax_checknumber(L, 2);
+ ps->setParticleAngularSpeed(n);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleSpritesMode(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ int n = luax_checkinteger(L, 2);
+ SpriteMode mode = static_cast<SpriteMode>(n);
+ ps->setParticleSpritesMode(mode);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_addParticleSprite(lua_State* L)
+ {
+ LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
+ ParticleSystem* ps = obj->getObject<ParticleSystem>();
+ LuaObject* objSpr = luax_checkobject(L, 2, Jin_Lua_Sprite);
+ Sprite* spr = objSpr->getObject<Sprite>();
+ ps->addParticleSprite(spr);
+ int depn = (*obj).getDependenciesCount();
+ (*obj).setDependency((int)ParticleSystemDependency::DEP_SPRITES + depn, objSpr);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_addParticleSprites(lua_State* L)
+ {
+ LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
+ ParticleSystem* ps = obj->getObject<ParticleSystem>();
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "sprites table");
+ return 1;
+ }
+ int n = luax_tableidxlen(L, 2);
+ int depn = (*obj).getDependenciesCount();
+ for (int i = 1; i <= n; ++i)
+ {
+ luax_rawgeti(L, 2, i);
+ LuaObject* objSpr = luax_checkobject(L, -1, Jin_Lua_Sprite);
+ luax_pop(L, 1);
+ Sprite* spr = objSpr->getObject<Sprite>();
+ ps->addParticleSprite(spr);
+ (*obj).setDependency((int)ParticleSystemDependency::DEP_SPRITES + depn + i - 1, objSpr);
+ }
+ return 0;
+ }
+
+ // From 0
+ LUA_IMPLEMENT int l_removeParticleSprite(lua_State* L)
+ {
+ LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
+ ParticleSystem* ps = obj->getObject<ParticleSystem>();
+ int n = luax_checkinteger(L, 2);
+ ps->removeParticleSprite(n);
+ (*obj).removeDependency((int)ParticleSystemDependency::DEP_SPRITES + n);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_enableParticleBlendAdditive(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ bool enable = luax_checkbool(L, 2);
+ ps->enableParticleBlendAdditive(enable);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleScale(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ float scale = luax_checknumber(L, 2);
+ ps->setParticleScale(scale);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_addParticleScalePoint(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ float scale = luax_checknumber(L, 2);
+ float t = luax_checknumber(L, 3);
+ ps->addParticleScalePoint(scale, t);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_removeParticleScalePoint(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ int i = luax_checkinteger(L, 2);
+ ps->removeParticleScalePoint(i);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleColor(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "color table");
+ return 1;
+ }
+ Color c;
+ c.r = luax_rawgetnumber(L, 2, 1);
+ c.g = luax_rawgetnumber(L, 2, 2);
+ c.b = luax_rawgetnumber(L, 2, 3);
+ c.a = luax_rawgetnumber(L, 2, 4);
+ ps->setParticleColor(c);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_addParticleColorPoint(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "color table");
+ return 1;
+ }
+ Color c;
+ c.r = luax_rawgetnumber(L, 2, 1);
+ c.g = luax_rawgetnumber(L, 2, 2);
+ c.b = luax_rawgetnumber(L, 2, 3);
+ c.a = luax_rawgetnumber(L, 2, 4);
+ float t = luax_checknumber(L, 3);
+ ps->addParticleColorPoint(c, t);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_removeParticleColorPoint(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ int i = luax_checkinteger(L, 2);
+ ps->removeParticleColorPoint(i);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleTransparency(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ float transparency = luax_checknumber(L, 2);
+ ps->setParticleTransparency(transparency);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_addParticleTransparencyPoint(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ float transparency = luax_checknumber(L, 2);
+ float t = luax_checknumber(L, 3);
+ ps->addParticleTransparencyPoint(transparency, t);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_removeParticleTransparencyPoint(lua_State* L)
+ {
+ ParticleSystem* ps = checkPS(L);
+ int i = luax_checkinteger(L, 2);
+ ps->removeParticleTransparencyPoint(i);
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_ParticleSystem(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "update", l_update },
+ { "render", l_render },
+ { "setPosition", l_setPosition },
+ { "setScale", l_setScale },
+ { "pause", l_pause },
+ { "clear", l_clear },
+ { "setEmitRate", l_setEmitRate },
+ { "setEmitForce", l_setEmitForce },
+ { "setEmitDirection", l_setEmitDirection },
+ { "setEmitPosition", l_setEmitPosition },
+ { "setParticleLife", l_setParticleLife },
+ { "setParticleLinearAccelaration", l_setParticleLinearAccelaration },
+ { "setParticleRadialAccelaration", l_setParticleRadialAccelaration },
+ { "setParticleAngularSpeed", l_setParticleAngularSpeed },
+ { "setParticleSpritesMode", l_setParticleSpritesMode },
+ { "addParticleSprite", l_addParticleSprite },
+ { "addParticleSprites", l_addParticleSprites },
+ { "removeParticleSprite", l_removeParticleSprite },
+ { "enableParticleBlendAdditive", l_enableParticleBlendAdditive },
+ { "setParticleScale", l_setParticleScale },
+ { "addParticleScalePoint", l_addParticleScalePoint },
+ { "removeParticleScalePoint", l_removeParticleScalePoint },
+ { "setParticleColor", l_setParticleColor },
+ { "addParticleColorPoint", l_addParticleColorPoint },
+ { "removeParticleColorPoint", l_removeParticleColorPoint },
+ { "setParticleTransparency", l_setParticleTransparency },
+ { "addParticleTransparencyPoint", l_addParticleTransparencyPoint },
+ { "removeParticleTransparencyPoint", l_removeParticleTransparencyPoint },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_ParticleSystem, methods);
+ }
+
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_particle_system.h b/src/libjin-lua/modules/graphics/l_particle_system.h
index b75b569..fb0616d 100644
--- a/src/libjin-lua/modules/graphics/l_particle_system.h
+++ b/src/libjin-lua/modules/graphics/l_particle_system.h
@@ -3,19 +3,19 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- enum class ParticleSystemDependency
- {
- DEP_SPRITES = 1,
- };
+ enum class ParticleSystemDependency
+ {
+ DEP_SPRITES = 1,
+ };
- extern const char* Jin_Lua_ParticleSystem;
+ extern const char* Jin_Lua_ParticleSystem;
- void luaopen_ParticleSystem(lua_State* L);
+ void luaopen_ParticleSystem(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_shader.cpp b/src/libjin-lua/modules/graphics/l_shader.cpp
index bdf82b4..4fda837 100644
--- a/src/libjin-lua/modules/graphics/l_shader.cpp
+++ b/src/libjin-lua/modules/graphics/l_shader.cpp
@@ -11,122 +11,122 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- const char* Jin_Lua_Shader = "Shader";
+ const char* Jin_Lua_Shader = "Shader";
- static inline Shader* checkShader(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Shader);
- return luaObj->getObject<Shader>();
- }
-
- /**
- * jsl:sendNumber("variable", 0.1)
- */
- LUA_IMPLEMENT int l_sendNumber(lua_State* L)
- {
- Shader* shader = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- float number = luax_checknumber(L, 3);
- shader->sendFloat(variable, number);
- return 0;
- }
+ static inline Shader* checkShader(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Shader);
+ return luaObj->getObject<Shader>();
+ }
+
+ /**
+ * jsl:sendNumber("variable", 0.1)
+ */
+ LUA_IMPLEMENT int l_sendNumber(lua_State* L)
+ {
+ Shader* shader = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ float number = luax_checknumber(L, 3);
+ shader->sendFloat(variable, number);
+ return 0;
+ }
- LUA_IMPLEMENT int l_sendTexture(lua_State* L)
- {
- Shader* shader = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 3, Jin_Lua_Texture);
- shader->sendTexture(variable, luaObj->getObject<Texture>());
- return 0;
- }
+ LUA_IMPLEMENT int l_sendTexture(lua_State* L)
+ {
+ Shader* shader = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 3, Jin_Lua_Texture);
+ shader->sendTexture(variable, luaObj->getObject<Texture>());
+ return 0;
+ }
- LUA_IMPLEMENT int l_sendCanvas(lua_State* L)
- {
- Shader* shader = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 3, Jin_Lua_Canvas);
- shader->sendCanvas(variable, luaObj->getObject<Canvas>());
- return 0;
- }
+ LUA_IMPLEMENT int l_sendCanvas(lua_State* L)
+ {
+ Shader* shader = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 3, Jin_Lua_Canvas);
+ shader->sendCanvas(variable, luaObj->getObject<Canvas>());
+ return 0;
+ }
- LUA_IMPLEMENT int l_sendVec2(lua_State* L)
- {
- Shader* shader = 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);
- shader->sendVec2(variable, x, y);
- return 0;
- }
+ LUA_IMPLEMENT int l_sendVec2(lua_State* L)
+ {
+ Shader* shader = 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);
+ shader->sendVec2(variable, x, y);
+ return 0;
+ }
- LUA_IMPLEMENT int l_sendVec3(lua_State* L)
- {
- Shader* shader = 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);
- shader->sendVec3(variable, x, y, z);
- return 0;
- }
+ LUA_IMPLEMENT int l_sendVec3(lua_State* L)
+ {
+ Shader* shader = 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);
+ shader->sendVec3(variable, x, y, z);
+ return 0;
+ }
- LUA_IMPLEMENT int l_sendVec4(lua_State* L)
- {
- Shader* shader = 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);
- shader->sendVec4(variable, x, y, z, w);
- return 0;
- }
+ LUA_IMPLEMENT int l_sendVec4(lua_State* L)
+ {
+ Shader* shader = 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);
+ shader->sendVec4(variable, x, y, z, w);
+ return 0;
+ }
- LUA_IMPLEMENT int l_sendColor(lua_State* L)
- {
- return l_sendVec4(L);
- }
+ LUA_IMPLEMENT int l_sendColor(lua_State* L)
+ {
+ return l_sendVec4(L);
+ }
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Shader);
- luaObj->release();
- return 0;
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Shader);
+ luaObj->release();
+ return 0;
+ }
- LUA_EXPORT void luaopen_Shader(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__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, methods);
- }
+ LUA_EXPORT void luaopen_Shader(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__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, methods);
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_shader.h b/src/libjin-lua/modules/graphics/l_shader.h
index 5a84372..39b6a07 100644
--- a/src/libjin-lua/modules/graphics/l_shader.h
+++ b/src/libjin-lua/modules/graphics/l_shader.h
@@ -3,14 +3,14 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_Shader;
+ extern const char* Jin_Lua_Shader;
- void luaopen_Shader(lua_State* L);
+ void luaopen_Shader(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_sprite.cpp b/src/libjin-lua/modules/graphics/l_sprite.cpp
index 1469042..9296a6d 100644
--- a/src/libjin-lua/modules/graphics/l_sprite.cpp
+++ b/src/libjin-lua/modules/graphics/l_sprite.cpp
@@ -13,54 +13,54 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Lua
- {
- const char* Jin_Lua_Sprite = "Sprite";
+ namespace Lua
+ {
+ const char* Jin_Lua_Sprite = "Sprite";
- LUA_IMPLEMENT inline Sprite* checkSprite(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Sprite);
- return luaObj->getObject<Sprite>();
- }
+ LUA_IMPLEMENT inline Sprite* checkSprite(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ return luaObj->getObject<Sprite>();
+ }
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Sprite);
- p->release();
- return 0;
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ p->release();
+ return 0;
+ }
- LUA_IMPLEMENT int l_render(lua_State* L)
- {
- Sprite* sprite = checkSprite(L);
- float x = luax_checknumber(L, 2);
- float y = luax_checknumber(L, 3);
- float sx = luax_checknumber(L, 4);
- float sy = luax_checknumber(L, 5);
- float r = luax_checknumber(L, 6);
- sprite->render(x, y, sx, sy, r);
- return 0;
- }
+ LUA_IMPLEMENT int l_render(lua_State* L)
+ {
+ Sprite* sprite = checkSprite(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ float sx = luax_checknumber(L, 4);
+ float sy = luax_checknumber(L, 5);
+ float r = luax_checknumber(L, 6);
+ sprite->render(x, y, sx, sy, r);
+ return 0;
+ }
- LUA_IMPLEMENT int l_getSize(lua_State* L)
- {
- Sprite* sprite = checkSprite(L);
- Vector2<int> size = sprite->getSize();
- luax_pushinteger(L, size.x());
- luax_pushinteger(L, size.y());
- return 1;
- }
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ Sprite* sprite = checkSprite(L);
+ Vector2<int> size = sprite->getSize();
+ luax_pushinteger(L, size.x());
+ luax_pushinteger(L, size.y());
+ return 1;
+ }
- LUA_EXPORT void luaopen_Sprite(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "render", l_render },
- { "getSize", l_getSize },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_Sprite, methods);
- }
+ LUA_EXPORT void luaopen_Sprite(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "render", l_render },
+ { "getSize", l_getSize },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Sprite, methods);
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_sprite.h b/src/libjin-lua/modules/graphics/l_sprite.h
index 02c44bf..eec5461 100644
--- a/src/libjin-lua/modules/graphics/l_sprite.h
+++ b/src/libjin-lua/modules/graphics/l_sprite.h
@@ -3,22 +3,22 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- // Sprite dependency slots.
- enum class SpriteDependency
- {
- DEP_GRAPHIC = 1,
- DEP_SHADER = 2,
- DEP_SPRITESHEET = 3
- };
+ // Sprite dependency slots.
+ enum class SpriteDependency
+ {
+ DEP_GRAPHIC = 1,
+ DEP_SHADER = 2,
+ DEP_SPRITESHEET = 3
+ };
- extern const char* Jin_Lua_Sprite;
+ extern const char* Jin_Lua_Sprite;
- void luaopen_Sprite(lua_State* L);
+ void luaopen_Sprite(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_spritesheet.cpp b/src/libjin-lua/modules/graphics/l_spritesheet.cpp
index e8400c3..b720723 100644
--- a/src/libjin-lua/modules/graphics/l_spritesheet.cpp
+++ b/src/libjin-lua/modules/graphics/l_spritesheet.cpp
@@ -12,107 +12,107 @@ using namespace JinEngine::Graphics;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- const char* Jin_Lua_SpriteSheet = "SpriteSheet";
+ const char* Jin_Lua_SpriteSheet = "SpriteSheet";
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaSSheet = (LuaObject*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
- luaSSheet->release();
- return 0;
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaSSheet = (LuaObject*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
+ luaSSheet->release();
+ return 0;
+ }
- LUA_IMPLEMENT int l_newSprite(lua_State* L)
- {
- LuaObject* luaSSheet = (LuaObject*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
- SpriteSheet* sheet = luaSSheet->getObject<SpriteSheet>();
- Quad quad;
- quad.x = luax_rawgetnumberthenpop(L, 2, 1);
- quad.y = luax_rawgetnumberthenpop(L, 2, 2);
- quad.w = luax_rawgetnumberthenpop(L, 2, 3);
- quad.h = luax_rawgetnumberthenpop(L, 2, 4);
- Sprite* spr = nullptr;
- if (luax_gettop(L) >= 4)
- {
- float ox = luax_checknumber(L, 3);
- float oy = luax_checknumber(L, 4);
- spr = sheet->createSprite(quad, ox, oy);
- }
- else if (luax_gettop(L) == 3)
- {
- int o = luax_checkinteger(L, 3);
- Origin origin;
- origin = static_cast<Origin>(o);
- spr = sheet->createSprite(quad, origin);
- }
- Shared* shrSprite = new Shared(spr);
- LuaObject* luaSprite = luax_newinstance(L, Jin_Lua_Sprite, shrSprite);
- luaSprite->setDependency((int)SpriteDependency::DEP_SPRITESHEET, luaSSheet);
- return 1;
- }
+ LUA_IMPLEMENT int l_newSprite(lua_State* L)
+ {
+ LuaObject* luaSSheet = (LuaObject*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
+ SpriteSheet* sheet = luaSSheet->getObject<SpriteSheet>();
+ Quad quad;
+ quad.x = luax_rawgetnumberthenpop(L, 2, 1);
+ quad.y = luax_rawgetnumberthenpop(L, 2, 2);
+ quad.w = luax_rawgetnumberthenpop(L, 2, 3);
+ quad.h = luax_rawgetnumberthenpop(L, 2, 4);
+ Sprite* spr = nullptr;
+ if (luax_gettop(L) >= 4)
+ {
+ float ox = luax_checknumber(L, 3);
+ float oy = luax_checknumber(L, 4);
+ spr = sheet->createSprite(quad, ox, oy);
+ }
+ else if (luax_gettop(L) == 3)
+ {
+ int o = luax_checkinteger(L, 3);
+ Origin origin;
+ origin = static_cast<Origin>(o);
+ spr = sheet->createSprite(quad, origin);
+ }
+ Shared* shrSprite = new Shared(spr);
+ LuaObject* luaSprite = luax_newinstance(L, Jin_Lua_Sprite, shrSprite);
+ luaSprite->setDependency((int)SpriteDependency::DEP_SPRITESHEET, luaSSheet);
+ return 1;
+ }
- // {} = newSprites
- LUA_IMPLEMENT int l_newSprites(lua_State* L)
- {
- LuaObject* luaSS = (LuaObject*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
- SpriteSheet* ss = luaSS->getObject<SpriteSheet>();
- int count = luax_checkinteger(L, 2);
- int r = luax_checkinteger(L, 3);
- int c = luax_checkinteger(L, 4);
- int w = luax_checkinteger(L, 5);
- int h = luax_checkinteger(L, 6);
- vector<Sprite*> sprs;
- int argc = luax_gettop(L);
- if (argc == 6)
- {
- sprs = ss->createSprites(count, r, c, w, h, Origin::TOPLEFT);
- }
- else if (argc >= 8)
- {
- int ox = luax_checkinteger(L, 7);
- int oy = luax_checkinteger(L, 8);
- int offx = luax_optinteger(L, 9, 0);
- int offy = luax_optinteger(L, 10, 0);
- sprs = ss->createSprites(count, r, c, w, h, ox, oy, offx, offy);
- }
- else if (argc >= 7)
- {
- int o = luax_checkinteger(L, 7);
- Origin origin = static_cast<Origin>(o);
- int offx = luax_optinteger(L, 8, 0);
- int offy = luax_optinteger(L, 9, 0);
- sprs = ss->createSprites(count, r, c, w, h, origin, offx, offy);
- }
- else
- {
- luax_error(L, "No matched override function.");
- return 1;
- }
- luax_newtable(L);
- LuaObject* graphic = luaSS->getDependency((int)SpriteSheetDependency::DEP_GRAPHIC);
- for (int i = 0; i < sprs.size(); ++i)
- {
- Sprite* spr = sprs[i];
- Shared* shrSpr = new Shared(spr);
- LuaObject* luaSpr = (LuaObject*)luax_newinstance(L, Jin_Lua_Sprite, shrSpr);
- luaSpr->setDependency((int)SpriteDependency::DEP_GRAPHIC, graphic);
- luax_rawseti(L, -2, i + 1);
- }
- return 1;
- }
+ // {} = newSprites
+ LUA_IMPLEMENT int l_newSprites(lua_State* L)
+ {
+ LuaObject* luaSS = (LuaObject*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
+ SpriteSheet* ss = luaSS->getObject<SpriteSheet>();
+ int count = luax_checkinteger(L, 2);
+ int r = luax_checkinteger(L, 3);
+ int c = luax_checkinteger(L, 4);
+ int w = luax_checkinteger(L, 5);
+ int h = luax_checkinteger(L, 6);
+ vector<Sprite*> sprs;
+ int argc = luax_gettop(L);
+ if (argc == 6)
+ {
+ sprs = ss->createSprites(count, r, c, w, h, Origin::TOPLEFT);
+ }
+ else if (argc >= 8)
+ {
+ int ox = luax_checkinteger(L, 7);
+ int oy = luax_checkinteger(L, 8);
+ int offx = luax_optinteger(L, 9, 0);
+ int offy = luax_optinteger(L, 10, 0);
+ sprs = ss->createSprites(count, r, c, w, h, ox, oy, offx, offy);
+ }
+ else if (argc >= 7)
+ {
+ int o = luax_checkinteger(L, 7);
+ Origin origin = static_cast<Origin>(o);
+ int offx = luax_optinteger(L, 8, 0);
+ int offy = luax_optinteger(L, 9, 0);
+ sprs = ss->createSprites(count, r, c, w, h, origin, offx, offy);
+ }
+ else
+ {
+ luax_error(L, "No matched override function.");
+ return 1;
+ }
+ luax_newtable(L);
+ LuaObject* graphic = luaSS->getDependency((int)SpriteSheetDependency::DEP_GRAPHIC);
+ for (int i = 0; i < sprs.size(); ++i)
+ {
+ Sprite* spr = sprs[i];
+ Shared* shrSpr = new Shared(spr);
+ LuaObject* luaSpr = (LuaObject*)luax_newinstance(L, Jin_Lua_Sprite, shrSpr);
+ luaSpr->setDependency((int)SpriteDependency::DEP_GRAPHIC, graphic);
+ luax_rawseti(L, -2, i + 1);
+ }
+ return 1;
+ }
- LUA_EXPORT void luaopen_SpriteSheet(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "newSprite", l_newSprite },
- { "newSprites", l_newSprites },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_SpriteSheet, methods);
- }
+ LUA_EXPORT void luaopen_SpriteSheet(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "newSprite", l_newSprite },
+ { "newSprites", l_newSprites },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_SpriteSheet, methods);
+ }
- }
+ }
} \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_spritesheet.h b/src/libjin-lua/modules/graphics/l_spritesheet.h
index bcae60b..9395e3d 100644
--- a/src/libjin-lua/modules/graphics/l_spritesheet.h
+++ b/src/libjin-lua/modules/graphics/l_spritesheet.h
@@ -3,19 +3,19 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- enum class SpriteSheetDependency
- {
- DEP_GRAPHIC = 1
- };
+ enum class SpriteSheetDependency
+ {
+ DEP_GRAPHIC = 1
+ };
- extern const char* Jin_Lua_SpriteSheet;
+ extern const char* Jin_Lua_SpriteSheet;
- void luaopen_SpriteSheet(lua_State* L);
+ void luaopen_SpriteSheet(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_text.cpp b/src/libjin-lua/modules/graphics/l_text.cpp
index b634947..d20018e 100644
--- a/src/libjin-lua/modules/graphics/l_text.cpp
+++ b/src/libjin-lua/modules/graphics/l_text.cpp
@@ -6,26 +6,26 @@ using namespace JinEngine::Graphics;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- const char* Jin_Lua_Text = "Text";
+ const char* Jin_Lua_Text = "Text";
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Text);
- p->release();
- return 0;
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Text);
+ p->release();
+ return 0;
+ }
- LUA_EXPORT void luaopen_Text(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_Text, methods);
- }
+ LUA_EXPORT void luaopen_Text(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Text, methods);
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_text.h b/src/libjin-lua/modules/graphics/l_text.h
index dfcc9cc..db9c684 100644
--- a/src/libjin-lua/modules/graphics/l_text.h
+++ b/src/libjin-lua/modules/graphics/l_text.h
@@ -3,14 +3,14 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_Text;
+ extern const char* Jin_Lua_Text;
- void luaopen_Text(lua_State* L);
+ void luaopen_Text(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_texture.cpp b/src/libjin-lua/modules/graphics/l_texture.cpp
index efef2cb..ba69379 100644
--- a/src/libjin-lua/modules/graphics/l_texture.cpp
+++ b/src/libjin-lua/modules/graphics/l_texture.cpp
@@ -7,57 +7,57 @@ using namespace JinEngine::Graphics;
namespace JinEngine
{
- namespace Lua
- {
-
- const char* Jin_Lua_Texture = "Texture";
-
- LUA_IMPLEMENT inline Texture* checkTexture(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Texture);
- return luaObj->getObject<Texture>();
- }
-
- LUA_IMPLEMENT int l_getWidth(lua_State* L)
- {
- Texture* shared = checkTexture(L);
- luax_pushnumber(L, shared->getWidth());
- return 1;
- }
-
- LUA_IMPLEMENT int l_getHeight(lua_State *L)
- {
- Texture* shared = checkTexture(L);
- luax_pushnumber(L, shared->getHeight());
- return 1;
- }
-
- LUA_IMPLEMENT int l_getSize(lua_State* L)
- {
- Texture* shared = checkTexture(L);
- luax_pushnumber(L, shared->getWidth());
- luax_pushnumber(L, shared->getHeight());
- return 2;
- }
-
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Texture);
- luaObj->release();
- return 0;
- }
-
- LUA_EXPORT void luaopen_Texture(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_Texture, methods);
- }
-
- }// namespace Lua
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Texture = "Texture";
+
+ LUA_IMPLEMENT inline Texture* checkTexture(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Texture);
+ return luaObj->getObject<Texture>();
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ Texture* shared = checkTexture(L);
+ luax_pushnumber(L, shared->getWidth());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State *L)
+ {
+ Texture* shared = checkTexture(L);
+ luax_pushnumber(L, shared->getHeight());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ Texture* shared = checkTexture(L);
+ luax_pushnumber(L, shared->getWidth());
+ luax_pushnumber(L, shared->getHeight());
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Texture);
+ luaObj->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Texture(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Texture, methods);
+ }
+
+ }// namespace Lua
}// namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_texture.h b/src/libjin-lua/modules/graphics/l_texture.h
index c8bb71c..fe6a83d 100644
--- a/src/libjin-lua/modules/graphics/l_texture.h
+++ b/src/libjin-lua/modules/graphics/l_texture.h
@@ -3,14 +3,14 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_Texture;
+ extern const char* Jin_Lua_Texture;
- void luaopen_Texture(lua_State* L);
+ void luaopen_Texture(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_texture_font.cpp b/src/libjin-lua/modules/graphics/l_texture_font.cpp
index d9801ef..20ed739 100644
--- a/src/libjin-lua/modules/graphics/l_texture_font.cpp
+++ b/src/libjin-lua/modules/graphics/l_texture_font.cpp
@@ -10,54 +10,54 @@ using namespace JinEngine::Graphics::Fonts;
namespace JinEngine
{
- namespace Lua
- {
-
- const char* Jin_Lua_TextureFont = "TextureFont";
-
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TextureFont);
- luaObj->release();
- return 0;
- }
-
- /* typeset(Text | string, lineheight, spacing) */
- LUA_IMPLEMENT int l_typeset(lua_State* L)
- {
- LuaObject* luaTexFont = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TextureFont);
- TextureFont* tf = luaTexFont->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))
- {
- LuaObject* p2 = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Text);
- Text* text = p2->getObject<Text>();
- page = tf->typeset(*text, lineheight, spacing);
- }
- Shared* shrPage = new Shared(page);
- LuaObject* luaPage = luax_newinstance(L, Jin_Lua_Page, shrPage);
- luaPage->setDependency((int)PageDependency::DEP_TEXTURE_FONT, luaTexFont);
- return 1;
- }
-
- LUA_EXPORT void luaopen_TextureFont(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "typeset", l_typeset },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_TextureFont, methods);
- }
-
- } // namespace Lua
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TextureFont = "TextureFont";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TextureFont);
+ luaObj->release();
+ return 0;
+ }
+
+ /* typeset(Text | string, lineheight, spacing) */
+ LUA_IMPLEMENT int l_typeset(lua_State* L)
+ {
+ LuaObject* luaTexFont = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TextureFont);
+ TextureFont* tf = luaTexFont->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))
+ {
+ LuaObject* p2 = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Text);
+ Text* text = p2->getObject<Text>();
+ page = tf->typeset(*text, lineheight, spacing);
+ }
+ Shared* shrPage = new Shared(page);
+ LuaObject* luaPage = luax_newinstance(L, Jin_Lua_Page, shrPage);
+ luaPage->setDependency((int)PageDependency::DEP_TEXTURE_FONT, luaTexFont);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_TextureFont(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TextureFont, methods);
+ }
+
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_texture_font.h b/src/libjin-lua/modules/graphics/l_texture_font.h
index d1fffe5..ef57d48 100644
--- a/src/libjin-lua/modules/graphics/l_texture_font.h
+++ b/src/libjin-lua/modules/graphics/l_texture_font.h
@@ -3,14 +3,14 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_TextureFont;
+ extern const char* Jin_Lua_TextureFont;
- void luaopen_TextureFont(lua_State* L);
+ void luaopen_TextureFont(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_ttf.cpp b/src/libjin-lua/modules/graphics/l_ttf.cpp
index cc9db8e..4c74a4d 100644
--- a/src/libjin-lua/modules/graphics/l_ttf.cpp
+++ b/src/libjin-lua/modules/graphics/l_ttf.cpp
@@ -10,54 +10,54 @@ using namespace JinEngine::Graphics::Fonts;
namespace JinEngine
{
- namespace Lua
- {
-
- const char* Jin_Lua_TTF = "TTF";
-
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTF);
- luaObj->release();
- return 0;
- }
-
- /* typeset(Text | string, lineheight, spacing) */
- LUA_IMPLEMENT int l_typeset(lua_State* L)
- {
- LuaObject* luaTTF = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTF);
- TTF* ttf = luaTTF->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))
- {
- LuaObject* luaText = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Text);
- Text* text = luaText->getObject<Text>();
- page = ttf->typeset(*text, lineheight, spacing);
- }
- Shared* refPage = new Shared(page);
- LuaObject* luaPage = luax_newinstance(L, Jin_Lua_Page, refPage);
- luaPage->setDependency((int)PageDependency::DEP_TTF, luaTTF);
- return 1;
- }
-
- LUA_EXPORT void luaopen_TTF(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "typeset", l_typeset },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_TTF, methods);
- }
-
- } // namespace Lua
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TTF = "TTF";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTF);
+ luaObj->release();
+ return 0;
+ }
+
+ /* typeset(Text | string, lineheight, spacing) */
+ LUA_IMPLEMENT int l_typeset(lua_State* L)
+ {
+ LuaObject* luaTTF = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTF);
+ TTF* ttf = luaTTF->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))
+ {
+ LuaObject* luaText = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Text);
+ Text* text = luaText->getObject<Text>();
+ page = ttf->typeset(*text, lineheight, spacing);
+ }
+ Shared* refPage = new Shared(page);
+ LuaObject* luaPage = luax_newinstance(L, Jin_Lua_Page, refPage);
+ luaPage->setDependency((int)PageDependency::DEP_TTF, luaTTF);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_TTF(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TTF, methods);
+ }
+
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_ttf.h b/src/libjin-lua/modules/graphics/l_ttf.h
index bfe503d..587136a 100644
--- a/src/libjin-lua/modules/graphics/l_ttf.h
+++ b/src/libjin-lua/modules/graphics/l_ttf.h
@@ -3,14 +3,14 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_TTF;
+ extern const char* Jin_Lua_TTF;
- void luaopen_TTF(lua_State* L);
+ void luaopen_TTF(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_ttf_data.cpp b/src/libjin-lua/modules/graphics/l_ttf_data.cpp
index 1c8c653..9cc629e 100644
--- a/src/libjin-lua/modules/graphics/l_ttf_data.cpp
+++ b/src/libjin-lua/modules/graphics/l_ttf_data.cpp
@@ -10,40 +10,40 @@ using namespace JinEngine::Graphics::Fonts;
namespace JinEngine
{
- namespace Lua
- {
-
- const char* Jin_Lua_TTFData = "TTFData";
-
- LUA_IMPLEMENT int l_newTTF(lua_State* L)
- {
- LuaObject* luaTTFData = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTFData);
- int fontsize = luax_checkinteger(L, 2);
- TTFData* fontData = luaTTFData->getObject<TTFData>();
- TTF* font = fontData->createTTF(fontsize);
- Shared* shrTTF = new Shared(font);
- LuaObject* luaTTF = luax_newinstance(L, Jin_Lua_TTF, shrTTF);
- luaTTF->setDependency((int)TTFDependency::DEP_TTFDATA, luaTTFData);
- return 1;
- }
-
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTFData);
- p->release();
- return 0;
- }
-
- LUA_EXPORT void luaopen_TTFData(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "newTTF", l_newTTF },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_TTFData, methods);
-
- }
-
- } // namespace Lua
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TTFData = "TTFData";
+
+ LUA_IMPLEMENT int l_newTTF(lua_State* L)
+ {
+ LuaObject* luaTTFData = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTFData);
+ int fontsize = luax_checkinteger(L, 2);
+ TTFData* fontData = luaTTFData->getObject<TTFData>();
+ TTF* font = fontData->createTTF(fontsize);
+ Shared* shrTTF = new Shared(font);
+ LuaObject* luaTTF = luax_newinstance(L, Jin_Lua_TTF, shrTTF);
+ luaTTF->setDependency((int)TTFDependency::DEP_TTFDATA, luaTTFData);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTFData);
+ p->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_TTFData(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "newTTF", l_newTTF },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TTFData, methods);
+
+ }
+
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/graphics/l_ttf_data.h b/src/libjin-lua/modules/graphics/l_ttf_data.h
index 1fd832d..1777375 100644
--- a/src/libjin-lua/modules/graphics/l_ttf_data.h
+++ b/src/libjin-lua/modules/graphics/l_ttf_data.h
@@ -3,19 +3,19 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- enum class TTFDependency
- {
- DEP_TTFDATA = 1,
- };
+ enum class TTFDependency
+ {
+ DEP_TTFDATA = 1,
+ };
- extern const char* Jin_Lua_TTFData;
+ extern const char* Jin_Lua_TTFData;
- void luaopen_TTFData(lua_State* L);
+ void luaopen_TTFData(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/joypad/l_joypad.cpp b/src/libjin-lua/modules/joypad/l_joypad.cpp
index a955978..6027998 100644
--- a/src/libjin-lua/modules/joypad/l_joypad.cpp
+++ b/src/libjin-lua/modules/joypad/l_joypad.cpp
@@ -4,18 +4,18 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- LUA_EXPORT int luaopen_joypad(lua_State* L)
- {
- luaL_Reg methods[] = {
- { 0, 0 }
- };
- luax_newlib(L, methods);
+ LUA_EXPORT int luaopen_joypad(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { 0, 0 }
+ };
+ luax_newlib(L, methods);
- return 1;
- }
- /*SDL_JoystickGetButton*/
- } // namespace Lua
+ return 1;
+ }
+ /*SDL_JoystickGetButton*/
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/joypad/l_joypad.h b/src/libjin-lua/modules/joypad/l_joypad.h
index ec0e20f..48841ce 100644
--- a/src/libjin-lua/modules/joypad/l_joypad.h
+++ b/src/libjin-lua/modules/joypad/l_joypad.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_joypad(lua_State* L);
+ int luaopen_joypad(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/keyboard/l_keyboard.cpp b/src/libjin-lua/modules/keyboard/l_keyboard.cpp
index 4eba31d..21a7c43 100644
--- a/src/libjin-lua/modules/keyboard/l_keyboard.cpp
+++ b/src/libjin-lua/modules/keyboard/l_keyboard.cpp
@@ -3,15 +3,15 @@
namespace JinEngine
{
- namespace Lua
- {
- //https://wiki.libsdl.org/SDL_Keycode
+ namespace Lua
+ {
+ //https://wiki.libsdl.org/SDL_Keycode
- LUA_EXPORT int luaopen_keyboard(lua_State* L)
- {
- luax_newlib(L, 0);
- return 1;
- }
+ LUA_EXPORT int luaopen_keyboard(lua_State* L)
+ {
+ luax_newlib(L, 0);
+ return 1;
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/keyboard/l_keyboard.h b/src/libjin-lua/modules/keyboard/l_keyboard.h
index bf00f83..04327d0 100644
--- a/src/libjin-lua/modules/keyboard/l_keyboard.h
+++ b/src/libjin-lua/modules/keyboard/l_keyboard.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_keyboard(lua_State* L);
+ int luaopen_keyboard(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/math/l_math.cpp b/src/libjin-lua/modules/math/l_math.cpp
index f7caa16..7a60152 100644
--- a/src/libjin-lua/modules/math/l_math.cpp
+++ b/src/libjin-lua/modules/math/l_math.cpp
@@ -4,27 +4,27 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- LUA_IMPLEMENT int l_mod(lua_State* L)
- {
- int n = luax_checkinteger(L, 1);
- int m = luax_checkinteger(L, 2);
- int mod = n % m;
- luax_pushinteger(L, mod);
- return 1;
- }
+ LUA_IMPLEMENT int l_mod(lua_State* L)
+ {
+ int n = luax_checkinteger(L, 1);
+ int m = luax_checkinteger(L, 2);
+ int mod = n % m;
+ luax_pushinteger(L, mod);
+ return 1;
+ }
- LUA_EXPORT int luaopen_math(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "mod", l_mod },
- { 0, 0 }
- };
- luax_newlib(L, methods);
- return 1;
- }
+ LUA_EXPORT int luaopen_math(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "mod", l_mod },
+ { 0, 0 }
+ };
+ luax_newlib(L, methods);
+ return 1;
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/math/l_math.h b/src/libjin-lua/modules/math/l_math.h
index 2e7010c..5ffde76 100644
--- a/src/libjin-lua/modules/math/l_math.h
+++ b/src/libjin-lua/modules/math/l_math.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_math(lua_State* L);
+ int luaopen_math(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/mouse/l_mouse.cpp b/src/libjin-lua/modules/mouse/l_mouse.cpp
index f6864ee..2f0dfb4 100644
--- a/src/libjin-lua/modules/mouse/l_mouse.cpp
+++ b/src/libjin-lua/modules/mouse/l_mouse.cpp
@@ -6,37 +6,37 @@ using namespace JinEngine::Input;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- LUA_IMPLEMENT int l_pos(lua_State* L)
- {
- static Mouse* mouse = Mouse::get();
- int x, y;
- mouse->getState(&x, &y);
- luax_pushnumber(L, x);
- luax_pushnumber(L, y);
- return 2;
- }
+ LUA_IMPLEMENT int l_pos(lua_State* L)
+ {
+ static Mouse* mouse = Mouse::get();
+ int x, y;
+ mouse->getState(&x, &y);
+ luax_pushnumber(L, x);
+ luax_pushnumber(L, y);
+ return 2;
+ }
- LUA_IMPLEMENT int l_setVisible(lua_State* L)
- {
- bool visible = luax_checkbool(L, 1);
- Mouse* mouse = Mouse::get();
- mouse->setVisible(visible);
- return 0;
- }
-
- LUA_EXPORT int luaopen_mouse(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "getPosition", l_pos },
- { "setVisible", l_setVisible },
- { 0, 0 }
- };
- luax_newlib(L, methods);
- return 1;
- }
+ LUA_IMPLEMENT int l_setVisible(lua_State* L)
+ {
+ bool visible = luax_checkbool(L, 1);
+ Mouse* mouse = Mouse::get();
+ mouse->setVisible(visible);
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_mouse(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "getPosition", l_pos },
+ { "setVisible", l_setVisible },
+ { 0, 0 }
+ };
+ luax_newlib(L, methods);
+ return 1;
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/mouse/l_mouse.h b/src/libjin-lua/modules/mouse/l_mouse.h
index 09738f5..7a70873 100644
--- a/src/libjin-lua/modules/mouse/l_mouse.h
+++ b/src/libjin-lua/modules/mouse/l_mouse.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_mouse(lua_State* L);
+ int luaopen_mouse(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/net/l_buffer.cpp b/src/libjin-lua/modules/net/l_buffer.cpp
index 546787e..5170a58 100644
--- a/src/libjin-lua/modules/net/l_buffer.cpp
+++ b/src/libjin-lua/modules/net/l_buffer.cpp
@@ -7,130 +7,130 @@ using namespace JinEngine::Lua::Net;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- const char* Jin_Lua_Buffer = "Buffer";
+ const char* Jin_Lua_Buffer = "Buffer";
- static inline Net::Buffer* checkNetBuffer(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Buffer);
- return luaObj->getObject<Net::Buffer>();
- }
+ static inline Net::Buffer* checkNetBuffer(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Buffer);
+ return luaObj->getObject<Net::Buffer>();
+ }
- // net.Buffer:append(value) -> value_length
- LUA_IMPLEMENT int l_append(lua_State* L)
- {
- Buffer* buffer = checkNetBuffer(L);
- const int vp = 2;
- if (luax_isintegerstrict(L, vp))
- {
- int n = luax_checkinteger(L, vp);
- int size = sizeof(n);
- buffer->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);
- buffer->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);
- buffer->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;
- buffer->append(str, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else
- {
- luax_typerror(L, vp, "number, bool or string");
- return 0;
- }
- }
+ // net.Buffer:append(value) -> value_length
+ LUA_IMPLEMENT int l_append(lua_State* L)
+ {
+ Buffer* buffer = checkNetBuffer(L);
+ const int vp = 2;
+ if (luax_isintegerstrict(L, vp))
+ {
+ int n = luax_checkinteger(L, vp);
+ int size = sizeof(n);
+ buffer->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);
+ buffer->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);
+ buffer->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;
+ buffer->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)
- {
- Buffer* buffer = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- unsigned int len;
- char* data = buffer->grabString(&len, offset);
- Array<char> str;
- str.bind(data, len);
- luax_pushstring(L, &str);
- luax_pushinteger(L, str.count());
- return 2;
- }
+ // net.Buffer:grabString(offset) -> string, length
+ LUA_IMPLEMENT int l_grabString(lua_State* L)
+ {
+ Buffer* buffer = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ unsigned int len;
+ char* data = buffer->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)
- {
- Buffer* buffer = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- int integer = buffer->grabInteger(&len, offset);
- luax_pushinteger(L, integer);
- luax_pushinteger(L, len);
- return 2;
- }
+ // net.Buffer:grabInteger(offset) -> integer, length
+ LUA_IMPLEMENT int l_grabInteger(lua_State* L)
+ {
+ Buffer* buffer = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ int integer = buffer->grabInteger(&len, offset);
+ luax_pushinteger(L, integer);
+ luax_pushinteger(L, len);
+ return 2;
+ }
- LUA_IMPLEMENT int l_grabFloat(lua_State* L)
- {
- Buffer* buffer = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- float floatv = buffer->grabFloat(&len, offset);
- luax_pushnumber(L, floatv);
- luax_pushinteger(L, len);
- return 2;
- }
+ LUA_IMPLEMENT int l_grabFloat(lua_State* L)
+ {
+ Buffer* buffer = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ float floatv = buffer->grabFloat(&len, offset);
+ luax_pushnumber(L, floatv);
+ luax_pushinteger(L, len);
+ return 2;
+ }
- LUA_IMPLEMENT int l_grabBoolean(lua_State* L)
- {
- Buffer* buffer = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- bool boolean = buffer->grabBoolean(&len, offset);
- luax_pushboolean(L, boolean);
- luax_pushinteger(L, len);
- return 2;
- }
+ LUA_IMPLEMENT int l_grabBoolean(lua_State* L)
+ {
+ Buffer* buffer = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ bool boolean = buffer->grabBoolean(&len, offset);
+ luax_pushboolean(L, boolean);
+ luax_pushinteger(L, len);
+ return 2;
+ }
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Buffer);
- luaObj->release();
- return 0;
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Buffer);
+ luaObj->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 }
- };
+ 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);
- }
+ luax_newtype(L, Jin_Lua_Buffer, netbuffer_function);
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/net/l_buffer.h b/src/libjin-lua/modules/net/l_buffer.h
index 4ff9be6..7cf6061 100644
--- a/src/libjin-lua/modules/net/l_buffer.h
+++ b/src/libjin-lua/modules/net/l_buffer.h
@@ -7,96 +7,96 @@
namespace JinEngine
{
- namespace Lua
- {
-
- extern const char* Jin_Lua_Buffer;
-
- void luaopen_Buffer(lua_State* L);
-
- namespace Net
- {
-
- class Buffer : public Object
- {
- public:
- Buffer(size_t s = 0)
- : size(s)
- {
- buffer = new char[size];
- memset(buffer, 0, size);
- }
-
- Buffer(const char* data, size_t s)
- : size(s)
- {
- buffer = new char[size];
- memcpy(buffer, data, size);
- }
-
- ~Buffer()
- {
- if (buffer != nullptr)
- {
- delete[] buffer;
- buffer = nullptr;
- size = 0;
- }
- }
-
- void append(const void* data, size_t s)
- {
- if (data == nullptr)
- return;
- char* buf = buffer;
- buffer = new char[size + s];
- memcpy(buffer, buf, size);
- memcpy(buffer + size, data, s);
- delete[] buf;
- size += s;
- return;
- }
-
- /* grab and create a string */
- char* grabString(unsigned int* length, int offset = 0)
- {
- int l = offset;
- for (; l < size; ++l)
- {
- if (buffer[l] == 0)
- break;
- }
- *length = l - offset + 1;
- char* str = (char*)malloc(*length);
- memcpy(str, buffer + offset, *length);
- return str;
- }
-
- int grabInteger(int* length, int offset = 0)
- {
- *length = sizeof(int);
- return *((int*)(buffer + offset));
- }
-
- float grabFloat(int* length, int offset = 0)
- {
- *length = sizeof(float);
- return *((float*)(buffer + offset));
- }
-
- bool grabBoolean(int* length, int offset = 0)
- {
- *length = sizeof(bool);
- return *((bool*)(buffer + offset));
- }
-
- char* buffer;
- size_t size;
-
- };
-
- } // namespace Net
- } // namespace Lua
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Buffer;
+
+ void luaopen_Buffer(lua_State* L);
+
+ namespace Net
+ {
+
+ class Buffer : public Object
+ {
+ public:
+ Buffer(size_t s = 0)
+ : size(s)
+ {
+ buffer = new char[size];
+ memset(buffer, 0, size);
+ }
+
+ Buffer(const char* data, size_t s)
+ : size(s)
+ {
+ buffer = new char[size];
+ memcpy(buffer, data, size);
+ }
+
+ ~Buffer()
+ {
+ if (buffer != nullptr)
+ {
+ delete[] buffer;
+ buffer = nullptr;
+ size = 0;
+ }
+ }
+
+ void append(const void* data, size_t s)
+ {
+ if (data == nullptr)
+ return;
+ char* buf = buffer;
+ buffer = new char[size + s];
+ memcpy(buffer, buf, size);
+ memcpy(buffer + size, data, s);
+ delete[] buf;
+ size += s;
+ return;
+ }
+
+ /* grab and create a string */
+ char* grabString(unsigned int* length, int offset = 0)
+ {
+ int l = offset;
+ for (; l < size; ++l)
+ {
+ if (buffer[l] == 0)
+ break;
+ }
+ *length = l - offset + 1;
+ char* str = (char*)malloc(*length);
+ memcpy(str, buffer + offset, *length);
+ return str;
+ }
+
+ int grabInteger(int* length, int offset = 0)
+ {
+ *length = sizeof(int);
+ return *((int*)(buffer + offset));
+ }
+
+ float grabFloat(int* length, int offset = 0)
+ {
+ *length = sizeof(float);
+ return *((float*)(buffer + offset));
+ }
+
+ bool grabBoolean(int* length, int offset = 0)
+ {
+ *length = sizeof(bool);
+ return *((bool*)(buffer + offset));
+ }
+
+ char* buffer;
+ size_t size;
+
+ };
+
+ } // namespace Net
+ } // namespace Lua
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/net/l_net.cpp b/src/libjin-lua/modules/net/l_net.cpp
index 5569381..512cf9a 100644
--- a/src/libjin-lua/modules/net/l_net.cpp
+++ b/src/libjin-lua/modules/net/l_net.cpp
@@ -7,73 +7,73 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- using namespace JinEngine::Lua::Net;
- using namespace JinEngine::Net;
+ using namespace JinEngine::Lua::Net;
+ using namespace JinEngine::Net;
- LUA_IMPLEMENT int l_initNetwork(lua_State* L)
- {
- JinEngine::Net::NetManager::get()->start();
- return 1;
- }
-
- LUA_IMPLEMENT int l_Socket(lua_State* L)
- {
- SocketInformation info = { 0 };
- {
- const char* socketType = luax_checkstring(L, 1);
- if (strcmp(socketType, "TCP") == 0)
- info.type = SocketType::TCP;
- else if (strcmp(socketType, "UDP") == 0)
- info.type = SocketType::UDP;
- else
- {
- luax_error(L, "jin.net.Socket() first paramter wrong, must be TCP or UDP");
- return 0;
- }
- // type, port
- if (luax_gettop(L) == 2)
- {
- info.port = luax_checkinteger(L, 2);
- }
- // type, address, port
- else if (luax_gettop(L) == 3)
- {
- if (luax_isstringstrict(L, 2))
- info.address = tk_strtohl(luax_checkstring(L, 2));
- else if (luax_isintegerstrict(L, 2))
- info.address = luax_checkinteger(L, 2);
- info.port = luax_checkinteger(L, 3);
- }
- }
- Socket* socket = new Socket(info);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Socket, new Shared(socket));
- return 1;
- }
+ LUA_IMPLEMENT int l_initNetwork(lua_State* L)
+ {
+ JinEngine::Net::NetManager::get()->start();
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_Socket(lua_State* L)
+ {
+ SocketInformation info = { 0 };
+ {
+ const char* socketType = luax_checkstring(L, 1);
+ if (strcmp(socketType, "TCP") == 0)
+ info.type = SocketType::TCP;
+ else if (strcmp(socketType, "UDP") == 0)
+ info.type = SocketType::UDP;
+ else
+ {
+ luax_error(L, "jin.net.Socket() first paramter wrong, must be TCP or UDP");
+ return 0;
+ }
+ // type, port
+ if (luax_gettop(L) == 2)
+ {
+ info.port = luax_checkinteger(L, 2);
+ }
+ // type, address, port
+ else if (luax_gettop(L) == 3)
+ {
+ if (luax_isstringstrict(L, 2))
+ info.address = tk_strtohl(luax_checkstring(L, 2));
+ else if (luax_isintegerstrict(L, 2))
+ info.address = luax_checkinteger(L, 2);
+ info.port = luax_checkinteger(L, 3);
+ }
+ }
+ Socket* socket = new Socket(info);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Socket, new Shared(socket));
+ return 1;
+ }
- LUA_IMPLEMENT int l_Buffer(lua_State* L)
- {
- int size = luax_checkinteger(L, 1);
- Net::Buffer* buffer = new Net::Buffer(size);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Buffer, new Shared(buffer));
- return 1;
- }
+ LUA_IMPLEMENT int l_Buffer(lua_State* L)
+ {
+ int size = luax_checkinteger(L, 1);
+ Net::Buffer* buffer = new Net::Buffer(size);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Buffer, new Shared(buffer));
+ return 1;
+ }
- LUA_EXPORT int luaopen_net(lua_State* L)
- {
- luaopen_Socket(L);
- luaopen_Buffer(L);
- luaL_Reg methods[] = {
- { "init", l_initNetwork },
- { "newSocket", l_Socket },
- { "newBuffer", l_Buffer },
- { 0, 0 }
- };
- luax_newlib(L, methods);
- return 1;
- }
+ LUA_EXPORT int luaopen_net(lua_State* L)
+ {
+ luaopen_Socket(L);
+ luaopen_Buffer(L);
+ luaL_Reg methods[] = {
+ { "init", l_initNetwork },
+ { "newSocket", l_Socket },
+ { "newBuffer", l_Buffer },
+ { 0, 0 }
+ };
+ luax_newlib(L, methods);
+ return 1;
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/net/l_net.h b/src/libjin-lua/modules/net/l_net.h
index 1542791..e41ed18 100644
--- a/src/libjin-lua/modules/net/l_net.h
+++ b/src/libjin-lua/modules/net/l_net.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_net(lua_State* L);
+ int luaopen_net(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/net/l_socket.cpp b/src/libjin-lua/modules/net/l_socket.cpp
index 1e86ea9..c5ed2b4 100644
--- a/src/libjin-lua/modules/net/l_socket.cpp
+++ b/src/libjin-lua/modules/net/l_socket.cpp
@@ -8,116 +8,116 @@ using namespace JinEngine::Lua::Net;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- const char* Jin_Lua_Socket = "Socket";
+ const char* Jin_Lua_Socket = "Socket";
- const int BUFFER_SIZE = 1024;
+ const int BUFFER_SIZE = 1024;
- LUA_IMPLEMENT inline Socket* checkSocket(lua_State* L, int pos = 1)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, pos, Jin_Lua_Socket);
- return luaObj->getObject<Socket>();
- }
+ LUA_IMPLEMENT inline Socket* checkSocket(lua_State* L, int pos = 1)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, pos, Jin_Lua_Socket);
+ return luaObj->getObject<Socket>();
+ }
- LUA_IMPLEMENT inline Buffer* checkNetBuffer(lua_State* L, int pos = 1)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, pos, Jin_Lua_Buffer);
- return luaObj->getObject<Buffer>();
- }
+ LUA_IMPLEMENT inline Buffer* checkNetBuffer(lua_State* L, int pos = 1)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, pos, Jin_Lua_Buffer);
+ return luaObj->getObject<Buffer>();
+ }
- // return net.Socket
- LUA_IMPLEMENT int l_accept(lua_State* L)
- {
- Socket* socket = checkSocket(L);
- Socket* client = socket->accept();
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Socket, new Shared(client));
- return 1;
- }
-
- // return net.Buffer
- LUA_IMPLEMENT int l_receive(lua_State* L)
- {
- Socket* socket = checkSocket(L);
- char buffer[BUFFER_SIZE] = {0};
- int size = socket->receive(buffer, BUFFER_SIZE);
- Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Buffer, new Shared(netBuffer));
- return 1;
- }
-
- // Socket:receiveFrom(address, port)
- LUA_IMPLEMENT int l_receiveFrom(lua_State* L)
- {
- Socket* 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);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Buffer, new Shared(netBuffer));
- return 1;
- }
+ // return net.Socket
+ LUA_IMPLEMENT int l_accept(lua_State* L)
+ {
+ Socket* socket = checkSocket(L);
+ Socket* client = socket->accept();
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Socket, new Shared(client));
+ return 1;
+ }
+
+ // return net.Buffer
+ LUA_IMPLEMENT int l_receive(lua_State* L)
+ {
+ Socket* socket = checkSocket(L);
+ char buffer[BUFFER_SIZE] = {0};
+ int size = socket->receive(buffer, BUFFER_SIZE);
+ Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Buffer, new Shared(netBuffer));
+ return 1;
+ }
+
+ // Socket:receiveFrom(address, port)
+ LUA_IMPLEMENT int l_receiveFrom(lua_State* L)
+ {
+ Socket* 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);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Buffer, new Shared(netBuffer));
+ return 1;
+ }
- // Socket:send(net.Buffer) -> data_length
- LUA_IMPLEMENT int l_send(lua_State* L)
- {
- Socket* socket = checkSocket(L);
- Buffer* buffer = checkNetBuffer(L, 2);
- int len = socket->send(buffer->buffer, buffer->size);
- luax_pushinteger(L, len);
- return 1;
- }
-
- // Socket:sendTo(address, port, net.Buffer)
- LUA_IMPLEMENT int l_sendTo(lua_State* L)
- {
- Socket* socket = checkSocket(L);
- int address = luax_checkinteger(L, 2);
- int port = luax_checkinteger(L, 3);
- Buffer* buffer = checkNetBuffer(L, 4);
- socket->sendTo(buffer->buffer, buffer->size, address, port);
- return 0;
- }
-
- LUA_IMPLEMENT int l_close(lua_State* L)
- {
- Socket* socket = checkSocket(L);
- socket->close();
- return 0;
- }
+ // Socket:send(net.Buffer) -> data_length
+ LUA_IMPLEMENT int l_send(lua_State* L)
+ {
+ Socket* socket = checkSocket(L);
+ Buffer* buffer = checkNetBuffer(L, 2);
+ int len = socket->send(buffer->buffer, buffer->size);
+ luax_pushinteger(L, len);
+ return 1;
+ }
+
+ // Socket:sendTo(address, port, net.Buffer)
+ LUA_IMPLEMENT int l_sendTo(lua_State* L)
+ {
+ Socket* socket = checkSocket(L);
+ int address = luax_checkinteger(L, 2);
+ int port = luax_checkinteger(L, 3);
+ Buffer* buffer = checkNetBuffer(L, 4);
+ socket->sendTo(buffer->buffer, buffer->size, address, port);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_close(lua_State* L)
+ {
+ Socket* socket = checkSocket(L);
+ socket->close();
+ return 0;
+ }
- LUA_IMPLEMENT int l_configBlocking(lua_State* L)
- {
- Socket* socket = checkSocket(L);
- bool blocking = luax_checkbool(L, 2);
- socket->configureBlocking(blocking);
- return 0;
- }
+ LUA_IMPLEMENT int l_configBlocking(lua_State* L)
+ {
+ Socket* socket = checkSocket(L);
+ bool blocking = luax_checkbool(L, 2);
+ socket->configureBlocking(blocking);
+ return 0;
+ }
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Socket);
- luaObj->release();
- return 0;
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Socket);
+ luaObj->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);
- }
+ 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 Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/net/l_socket.h b/src/libjin-lua/modules/net/l_socket.h
index b33fac6..54542e4 100644
--- a/src/libjin-lua/modules/net/l_socket.h
+++ b/src/libjin-lua/modules/net/l_socket.h
@@ -3,14 +3,14 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- extern const char* Jin_Lua_Socket;
+ extern const char* Jin_Lua_Socket;
- void luaopen_Socket(lua_State* L);
+ void luaopen_Socket(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/thread/l_thread.cpp b/src/libjin-lua/modules/thread/l_thread.cpp
index 757244a..4fef77a 100644
--- a/src/libjin-lua/modules/thread/l_thread.cpp
+++ b/src/libjin-lua/modules/thread/l_thread.cpp
@@ -7,234 +7,234 @@
namespace JinEngine
{
- namespace Lua
- {
-
- const char* Jin_Lua_Thread = "Thread";
-
- int luaopen_thread(lua_State* L);
-
- static inline Thread* checkThread(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Thread);
- return luaObj->getObject<Thread>();
- }
-
- LUA_IMPLEMENT int threadRunner(void* t)
- {
- Shared* shared = (Shared*)t;
- Thread* thread = shared->getObject<Thread>();
- lua_State* L = lua_open();
- luax_openlibs(L);
- open(L);
- luax_getglobal(L, MODULE_NAME);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Thread, shared);
- luax_setfield(L, -2, "_curThread");
- luax_dostring(L, thread->code.c_str());
- luax_close(L);
- return 0;
- }
-
- LUA_IMPLEMENT int l_thread_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Thread);
- luaObj->release();
- return 0;
- }
-
- LUA_IMPLEMENT int l_start(lua_State* L)
- {
- Thread* shared = checkThread(L);
- bool result = shared->start(&shared);
- luax_pushboolean(L, result);
- return 1;
- }
-
- LUA_IMPLEMENT int l_wait(lua_State* L)
- {
- Thread* shared = checkThread(L);
- shared->wait();
- return 0;
- }
-
- LUA_IMPLEMENT int l_send(lua_State* L)
- {
- Thread* 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))
- {
- LuaObject* luaObj = (LuaObject*)luax_touserdata(L, vp);
- shared->send(slot, luaObj);
- }/*
- 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)
- {
- Thread* 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)
- {
- Thread* 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:
- LuaObject* p = (LuaObject*)v.pointer;
- // Create lua object from other lua_State.
- LuaObject* luaObj = luax_copyinstance(L, p);
- break;
-
- }
- return 1;
- }
-
- LUA_IMPLEMENT int l_demand(lua_State* L)
- {
- Thread* 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:
- LuaObject* p = (LuaObject*)v.pointer;
- // Create lua object from other lua_State.
- LuaObject* luaObj = luax_copyinstance(L, p);
- break;
-
- }
- return 1;
- }
-
- LUA_IMPLEMENT int l_remove(lua_State* L)
- {
- Thread* shared = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- shared->remove(slot);
- return 0;
- }
-
- LUA_IMPLEMENT int l_getName(lua_State* L)
- {
- Thread* shared = checkThread(L);
- const char* name = shared->getName();
- luax_pushstring(L, name);
- return 1;
- }
-
- LUA_IMPLEMENT int l_isRunning(lua_State* L)
- {
- Thread* 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);
- Thread* thread = new Thread(name, code, threadRunner);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Thread, new Shared(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 methods[] = {
- { "newThread", l_newThread },
- { "getThread", l_getThread },
- { 0, 0 }
- };
- luax_newlib(L, methods);
- return 1;
- }
-
- } // namespace Lua
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Thread = "Thread";
+
+ int luaopen_thread(lua_State* L);
+
+ static inline Thread* checkThread(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Thread);
+ return luaObj->getObject<Thread>();
+ }
+
+ LUA_IMPLEMENT int threadRunner(void* t)
+ {
+ Shared* shared = (Shared*)t;
+ Thread* thread = shared->getObject<Thread>();
+ lua_State* L = lua_open();
+ luax_openlibs(L);
+ open(L);
+ luax_getglobal(L, MODULE_NAME);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Thread, shared);
+ luax_setfield(L, -2, "_curThread");
+ luax_dostring(L, thread->code.c_str());
+ luax_close(L);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_thread_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Thread);
+ luaObj->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_start(lua_State* L)
+ {
+ Thread* shared = checkThread(L);
+ bool result = shared->start(&shared);
+ luax_pushboolean(L, result);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_wait(lua_State* L)
+ {
+ Thread* shared = checkThread(L);
+ shared->wait();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_send(lua_State* L)
+ {
+ Thread* 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))
+ {
+ LuaObject* luaObj = (LuaObject*)luax_touserdata(L, vp);
+ shared->send(slot, luaObj);
+ }/*
+ 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)
+ {
+ Thread* 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)
+ {
+ Thread* 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:
+ LuaObject* p = (LuaObject*)v.pointer;
+ // Create lua object from other lua_State.
+ LuaObject* luaObj = luax_copyinstance(L, p);
+ break;
+
+ }
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_demand(lua_State* L)
+ {
+ Thread* 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:
+ LuaObject* p = (LuaObject*)v.pointer;
+ // Create lua object from other lua_State.
+ LuaObject* luaObj = luax_copyinstance(L, p);
+ break;
+
+ }
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_remove(lua_State* L)
+ {
+ Thread* shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ shared->remove(slot);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getName(lua_State* L)
+ {
+ Thread* shared = checkThread(L);
+ const char* name = shared->getName();
+ luax_pushstring(L, name);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_isRunning(lua_State* L)
+ {
+ Thread* 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);
+ Thread* thread = new Thread(name, code, threadRunner);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Thread, new Shared(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 methods[] = {
+ { "newThread", l_newThread },
+ { "getThread", l_getThread },
+ { 0, 0 }
+ };
+ luax_newlib(L, methods);
+ return 1;
+ }
+
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/thread/l_thread.h b/src/libjin-lua/modules/thread/l_thread.h
index 8203134..957abb1 100644
--- a/src/libjin-lua/modules/thread/l_thread.h
+++ b/src/libjin-lua/modules/thread/l_thread.h
@@ -3,93 +3,93 @@
namespace JinEngine
{
- namespace Lua
- {
-
- extern const char* Jin_Lua_Thread;
-
- class Thread : public Object
- {
- 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;
-
- };
-
- int luaopen_thread(lua_State* L);
-
- } // namespace Lua
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Thread;
+
+ class Thread : public Object
+ {
+ 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;
+
+ };
+
+ int luaopen_thread(lua_State* L);
+
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/time/l_time.cpp b/src/libjin-lua/modules/time/l_time.cpp
index 0e39f9e..b88b485 100644
--- a/src/libjin-lua/modules/time/l_time.cpp
+++ b/src/libjin-lua/modules/time/l_time.cpp
@@ -9,57 +9,57 @@ using namespace JinEngine::Time;
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- LUA_IMPLEMENT int l_sec(lua_State* L)
- {
- luax_pushnumber(L, getSecond());
- return 1;
- }
+ 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_sleep(lua_State* L)
+ {
+ double sec = luax_checknumber(L, 1);
+ sleep(sec * 1000.0f);
+ return 0;
+ }
- LUA_IMPLEMENT int l_newTimer(lua_State* L)
- {
- Shared* shrTimer = new Shared(new Timer());
- luax_newinstance(L, Jin_Lua_Timer, shrTimer);
- return 1;
- }
+ LUA_IMPLEMENT int l_newTimer(lua_State* L)
+ {
+ Shared* shrTimer = new Shared(new Timer());
+ luax_newinstance(L, Jin_Lua_Timer, shrTimer);
+ return 1;
+ }
- LUA_IMPLEMENT int l_getDelta(lua_State* L)
- {
- luax_pushnumber(L, Time::getDeltaTime());
- return 1;
- }
+ LUA_IMPLEMENT int l_getDelta(lua_State* L)
+ {
+ luax_pushnumber(L, Time::getDeltaTime());
+ return 1;
+ }
- LUA_IMPLEMENT int l_step(lua_State* L)
- {
- Time::step();
- return 0;
- }
-
- LUA_EXPORT int luaopen_time(lua_State* L)
- {
- // Types.
- luaopen_Timer(L);
- // Functions.
- luaL_Reg methods[] = {
- { "second", l_sec },
- { "sleep", l_sleep },
- { "newTimer", l_newTimer },
- { "step", l_step },
- { "getDelta", l_getDelta },
- { 0, 0 },
- };
- luax_newlib(L, methods);
- return 1;
- }
+ LUA_IMPLEMENT int l_step(lua_State* L)
+ {
+ Time::step();
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_time(lua_State* L)
+ {
+ // Types.
+ luaopen_Timer(L);
+ // Functions.
+ luaL_Reg methods[] = {
+ { "second", l_sec },
+ { "sleep", l_sleep },
+ { "newTimer", l_newTimer },
+ { "step", l_step },
+ { "getDelta", l_getDelta },
+ { 0, 0 },
+ };
+ luax_newlib(L, methods);
+ return 1;
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin-lua/modules/time/l_time.h b/src/libjin-lua/modules/time/l_time.h
index 3c75221..a92e33b 100644
--- a/src/libjin-lua/modules/time/l_time.h
+++ b/src/libjin-lua/modules/time/l_time.h
@@ -3,12 +3,12 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- int luaopen_time(lua_State* L);
+ int luaopen_time(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin-lua/modules/time/l_timer.cpp b/src/libjin-lua/modules/time/l_timer.cpp
index 8886913..82a1398 100644
--- a/src/libjin-lua/modules/time/l_timer.cpp
+++ b/src/libjin-lua/modules/time/l_timer.cpp
@@ -6,127 +6,127 @@ using namespace JinEngine::Time;
namespace JinEngine
{
- namespace Lua
- {
-
- const char* Jin_Lua_Timer = "Timer";
-
- const char* Jin_Lua_Handler = "Handler";
-
- 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 Timer* checkTimer(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Timer);
- return luaObj->getObject<Timer>();
- }
-
- // timer:every(time, callback, parameter)
- LUA_IMPLEMENT int l_every(lua_State* L)
- {
- int n = luax_gettop(L);
- Timer* shared = checkTimer(L);
- 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 = shared->every(s, timerCallback, func, finishCallback);
- Shared* shrHandler = new Shared(handler);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Handler, shrHandler);
- return 1;
- }
-
- // timer:after(time, callback, parameter)
- LUA_IMPLEMENT int l_after(lua_State* L)
- {
- int n = luax_gettop(L);
- Timer* shared = checkTimer(L);
- 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 = shared->after(s, timerCallback, func, finishCallback);
- Shared* shrHandler = new Shared(handler);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Handler, shrHandler);
- return 1;
- }
-
- // timer:repeat(time, callback, parameter)
- LUA_IMPLEMENT int l_repeat(lua_State* L)
- {
- int n = luax_gettop(L);
- Timer* shared = checkTimer(L);
- 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 = shared->repeat(s, count, timerCallback, func, finishCallback);
- Shared* shrHandler = new Shared(handler);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Handler, shrHandler);
- return 1;
- }
-
- LUA_IMPLEMENT int l_update(lua_State* L)
- {
- Timer* shared = checkTimer(L);
- float s = luax_checknumber(L, 2);
- shared->update(s);
- return 0;
- }
-
- LUA_IMPLEMENT int l_cancel(lua_State* L)
- {
- LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Timer);
- Timer* timer = p->getObject<Timer>();
- LuaObject* ph = (LuaObject*)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)
- {
- LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Timer);
- Timer* timer = p->getObject<Timer>();
- timer->cancelAll();
- return 0;
- }
-
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Timer);
- p->release();
- return 0;
- }
-
- LUA_EXPORT void luaopen_Timer(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__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, methods);
- }
-
- }
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Timer = "Timer";
+
+ const char* Jin_Lua_Handler = "Handler";
+
+ 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 Timer* checkTimer(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Timer);
+ return luaObj->getObject<Timer>();
+ }
+
+ // timer:every(time, callback, parameter)
+ LUA_IMPLEMENT int l_every(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ Timer* shared = checkTimer(L);
+ 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 = shared->every(s, timerCallback, func, finishCallback);
+ Shared* shrHandler = new Shared(handler);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Handler, shrHandler);
+ return 1;
+ }
+
+ // timer:after(time, callback, parameter)
+ LUA_IMPLEMENT int l_after(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ Timer* shared = checkTimer(L);
+ 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 = shared->after(s, timerCallback, func, finishCallback);
+ Shared* shrHandler = new Shared(handler);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Handler, shrHandler);
+ return 1;
+ }
+
+ // timer:repeat(time, callback, parameter)
+ LUA_IMPLEMENT int l_repeat(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ Timer* shared = checkTimer(L);
+ 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 = shared->repeat(s, count, timerCallback, func, finishCallback);
+ Shared* shrHandler = new Shared(handler);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Handler, shrHandler);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_update(lua_State* L)
+ {
+ Timer* shared = checkTimer(L);
+ float s = luax_checknumber(L, 2);
+ shared->update(s);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_cancel(lua_State* L)
+ {
+ LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Timer);
+ Timer* timer = p->getObject<Timer>();
+ LuaObject* ph = (LuaObject*)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)
+ {
+ LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Timer);
+ Timer* timer = p->getObject<Timer>();
+ timer->cancelAll();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Timer);
+ p->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Timer(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__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, methods);
+ }
+
+ }
} \ No newline at end of file
diff --git a/src/libjin-lua/modules/time/l_timer.h b/src/libjin-lua/modules/time/l_timer.h
index 35ec15d..e41bfd0 100644
--- a/src/libjin-lua/modules/time/l_timer.h
+++ b/src/libjin-lua/modules/time/l_timer.h
@@ -5,16 +5,16 @@
namespace JinEngine
{
- namespace Lua
- {
-
- extern const char* Jin_Lua_Timer;
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Timer;
- extern const char* Jin_Lua_Handler;
+ extern const char* Jin_Lua_Handler;
- void luaopen_Timer(lua_State* L);
+ void luaopen_Timer(lua_State* L);
- }
+ }
}
#endif \ No newline at end of file