aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lua/common/je_lua_reference.h2
-rw-r--r--src/lua/modules/audio/je_lua_audio.cpp24
-rw-r--r--src/lua/modules/audio/je_lua_source.cpp28
-rw-r--r--src/lua/modules/bit/je_lua_bit.cpp23
-rw-r--r--src/lua/modules/core/je_lua_core.cpp13
-rw-r--r--src/lua/modules/event/je_lua_event.cpp10
-rw-r--r--src/lua/modules/filesystem/je_lua_filesystem.cpp20
-rw-r--r--src/lua/modules/graphics/je_lua_bitmap.cpp23
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.cpp16
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp92
-rw-r--r--src/lua/modules/graphics/je_lua_page.cpp15
-rw-r--r--src/lua/modules/graphics/je_lua_shader.cpp23
-rw-r--r--src/lua/modules/graphics/je_lua_text.cpp9
-rw-r--r--src/lua/modules/graphics/je_lua_texture.cpp17
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.cpp13
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.cpp11
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.cpp12
-rw-r--r--src/lua/modules/joypad/je_lua_joypad.cpp7
-rw-r--r--src/lua/modules/math/je_lua_math.cpp9
-rw-r--r--src/lua/modules/mouse/je_lua_mouse.cpp11
-rw-r--r--src/lua/modules/net/je_lua_buffer.cpp199
-rw-r--r--src/lua/modules/net/je_lua_net.cpp15
-rw-r--r--src/lua/modules/net/je_lua_socket.cpp23
-rw-r--r--src/lua/modules/thread/je_lua_thread.cpp41
-rw-r--r--src/lua/modules/time/je_lua_time.cpp19
-rw-r--r--src/lua/modules/time/je_lua_timer.cpp22
26 files changed, 339 insertions, 358 deletions
diff --git a/src/lua/common/je_lua_reference.h b/src/lua/common/je_lua_reference.h
index bde61b6..d2d077f 100644
--- a/src/lua/common/je_lua_reference.h
+++ b/src/lua/common/je_lua_reference.h
@@ -27,7 +27,7 @@ namespace JinEngine
private:
lua_State* const mL;
- int mIndex;
+ int mIndex;
};
diff --git a/src/lua/modules/audio/je_lua_audio.cpp b/src/lua/modules/audio/je_lua_audio.cpp
index 45256e1..92e2e04 100644
--- a/src/lua/modules/audio/je_lua_audio.cpp
+++ b/src/lua/modules/audio/je_lua_audio.cpp
@@ -109,24 +109,24 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "init", l_init },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "setVolume", l_setVolume },
- { "newSource", l_newSource },
- { "destroy", l_destroy },
- { 0, 0 }
- };
-
LUA_PORT int luaopen_Source(lua_State* L);
LUA_EXPORT int luaopen_audio(lua_State* L)
{
luaopen_Source(L);
+ luaL_Reg f[] = {
+ { "init", l_init },
+ { "play", l_play },
+ { "stop", l_stop },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "setVolume", l_setVolume },
+ { "newSource", l_newSource },
+ { "destroy", l_destroy },
+ { 0, 0 }
+ };
+
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/audio/je_lua_source.cpp b/src/lua/modules/audio/je_lua_source.cpp
index 2297fea..a451995 100644
--- a/src/lua/modules/audio/je_lua_source.cpp
+++ b/src/lua/modules/audio/je_lua_source.cpp
@@ -91,23 +91,23 @@ namespace JinEngine
proxy->release();
return 0;
}
-
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "rewind", l_rewind },
- { "isStop", l_isStop },
- { "isPaused", l_isPaused },
- { "setVolume", l_setVolume },
- { "setLoop", l_setLoop },
- { 0, 0 }
- };
LUA_EXPORT int luaopen_Source(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "play", l_play },
+ { "stop", l_stop },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "rewind", l_rewind },
+ { "isStop", l_isStop },
+ { "isPaused", l_isPaused },
+ { "setVolume", l_setVolume },
+ { "setLoop", l_setLoop },
+ { 0, 0 }
+ };
+
luax_newtype(L, JIN_AUDIO_SOURCE, f);
return 0;
}
diff --git a/src/lua/modules/bit/je_lua_bit.cpp b/src/lua/modules/bit/je_lua_bit.cpp
index f182ebd..fdd0ae0 100644
--- a/src/lua/modules/bit/je_lua_bit.cpp
+++ b/src/lua/modules/bit/je_lua_bit.cpp
@@ -64,19 +64,20 @@ namespace JinEngine
return 1;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "bAnd", l_and },
- { "bOr" , l_or },
- { "bXor", l_xor },
- { "bNot", l_not },
- { "bLs", l_lshift },
- { "bRs", l_rshift },
- { "bInc", l_include },
- { 0, 0 }
- };
-
+
LUA_EXPORT int luaopen_bit(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "bAnd", l_and },
+ { "bOr" , l_or },
+ { "bXor", l_xor },
+ { "bNot", l_not },
+ { "bLs", l_lshift },
+ { "bRs", l_rshift },
+ { "bInc", l_include },
+ { 0, 0 }
+ };
+
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/core/je_lua_core.cpp b/src/lua/modules/core/je_lua_core.cpp
index 30d55a9..f5b06c3 100644
--- a/src/lua/modules/core/je_lua_core.cpp
+++ b/src/lua/modules/core/je_lua_core.cpp
@@ -29,15 +29,14 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "running", l_running },
- { "stop", l_stop },
- { "quit", l_quit },
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_core(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "running", l_running },
+ { "stop", l_stop },
+ { "quit", l_quit },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/event/je_lua_event.cpp b/src/lua/modules/event/je_lua_event.cpp
index d09108a..82ba385 100644
--- a/src/lua/modules/event/je_lua_event.cpp
+++ b/src/lua/modules/event/je_lua_event.cpp
@@ -111,18 +111,18 @@ namespace JinEngine
}
return 1;
}
-
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "poll", l_event_poll },
- { 0, 0 }
- };
/**
* load event module
*/
LUA_EXPORT int luaopen_event(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "poll", l_event_poll },
+ { 0, 0 }
+ };
luax_newlib(L, f);
+
return 1;
}
diff --git a/src/lua/modules/filesystem/je_lua_filesystem.cpp b/src/lua/modules/filesystem/je_lua_filesystem.cpp
index 3c3c12c..6245ba8 100644
--- a/src/lua/modules/filesystem/je_lua_filesystem.cpp
+++ b/src/lua/modules/filesystem/je_lua_filesystem.cpp
@@ -120,20 +120,20 @@ namespace JinEngine
return 2;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "init", l_init },
- { "mount", l_mount },
- { "isDirectory", l_isDir },
- { "isFile", l_isFile },
- { "exist", l_exist },
- { "read", l_read },
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_filesystem(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "init", l_init },
+ { "mount", l_mount },
+ { "isDirectory", l_isDir },
+ { "isFile", l_isFile },
+ { "exist", l_exist },
+ { "read", l_read },
+ { 0, 0 }
+ };
luax_newlib(L, f);
luax_registersearcher(L, loader, 1);
+
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_bitmap.cpp b/src/lua/modules/graphics/je_lua_bitmap.cpp
index 2a35ed5..1491bee 100644
--- a/src/lua/modules/graphics/je_lua_bitmap.cpp
+++ b/src/lua/modules/graphics/je_lua_bitmap.cpp
@@ -91,20 +91,19 @@ namespace JinEngine
proxy->bind(new Shared<Bitmap>(b, JIN_GRAPHICS_BITMAP));
return 1;
}
-
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { "getPixel", l_getPixel },
- { "setPixel", l_setPixel },
- { "clone", l_clone },
- { 0, 0 }
- };
-
+
LUA_EXPORT int luaopen_Bitmap(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { "getPixel", l_getPixel },
+ { "setPixel", l_setPixel },
+ { "clone", l_clone },
+ { 0, 0 }
+ };
luax_newtype(L, JIN_GRAPHICS_BITMAP, f);
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_canvas.cpp b/src/lua/modules/graphics/je_lua_canvas.cpp
index 42570b2..8d8630f 100644
--- a/src/lua/modules/graphics/je_lua_canvas.cpp
+++ b/src/lua/modules/graphics/je_lua_canvas.cpp
@@ -47,17 +47,17 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_Canvas(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { 0, 0 }
+ };
luax_newtype(L, JIN_GRAPHICS_CANVAS, f);
+
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 3ff5710..3155aa0 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -738,52 +738,6 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- /* window */
- { "init", l_init },
- { "setTitle", l_setTitle },
- { "getSize", l_getSize },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "destroy", l_destroy },
- { "hideWindow", l_hideWindow },
- { "showWindow", l_showWindow },
- /* creators */
- { "newBitmap", l_newBitmap },
- { "newTexture", l_newTexture },
- { "newShader", l_newShader },
- { "newShaderf", l_newShaderf },
- { "newCanvas", l_newCanvas },
- { "newTTFData", l_newTTFData },
- { "newText", l_newText },
- { "newTextureFont", l_newTextureFont },
- /* render */
- { "setClearColor", l_setClearColor },
- { "clear", l_clear },
- { "draw", l_draw },
- { "print", l_print },
- { "drawq", l_drawq },
- { "setColor", l_setColor },
- { "getColor", l_getColor },
- { "present", l_present },
- /* canvas */
- { "bindCanvas", l_bindCanvas },
- { "unbindCanvas", l_unbindCanvas },
- /* shader */
- { "useShader", l_useShader },
- /* shapes */
- { "point", l_point },
- { "line", l_line },
- { "rect", l_rect },
- { "circle", l_circle },
- { "triangle", l_triangle },
- { "polygon", l_polygon },
- /* font */
- { "setFont", l_setFont },
- { "unsetFont", l_unsetFont },
- { 0, 0 }
- };
-
LUA_PORT int luaopen_Texture(lua_State* L);
LUA_PORT int luaopen_Text(lua_State* L);
LUA_PORT int luaopen_TTF(lua_State* L);
@@ -806,6 +760,52 @@ namespace JinEngine
luaopen_TextureFont(L);
luaopen_Page(L);
luaopen_JSL(L);
+
+ luaL_Reg f[] = {
+ /* window */
+ { "init", l_init },
+ { "setTitle", l_setTitle },
+ { "getSize", l_getSize },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "destroy", l_destroy },
+ { "hideWindow", l_hideWindow },
+ { "showWindow", l_showWindow },
+ /* creators */
+ { "newBitmap", l_newBitmap },
+ { "newTexture", l_newTexture },
+ { "newShader", l_newShader },
+ { "newShaderf", l_newShaderf },
+ { "newCanvas", l_newCanvas },
+ { "newTTFData", l_newTTFData },
+ { "newText", l_newText },
+ { "newTextureFont", l_newTextureFont },
+ /* render */
+ { "setClearColor", l_setClearColor },
+ { "clear", l_clear },
+ { "draw", l_draw },
+ { "print", l_print },
+ { "drawq", l_drawq },
+ { "setColor", l_setColor },
+ { "getColor", l_getColor },
+ { "present", l_present },
+ /* canvas */
+ { "bindCanvas", l_bindCanvas },
+ { "unbindCanvas", l_unbindCanvas },
+ /* shader */
+ { "useShader", l_useShader },
+ /* shapes */
+ { "point", l_point },
+ { "line", l_line },
+ { "rect", l_rect },
+ { "circle", l_circle },
+ { "triangle", l_triangle },
+ { "polygon", l_polygon },
+ /* font */
+ { "setFont", l_setFont },
+ { "unsetFont", l_unsetFont },
+ { 0, 0 }
+ };
// load whole lib
luax_newlib(L, f);
diff --git a/src/lua/modules/graphics/je_lua_page.cpp b/src/lua/modules/graphics/je_lua_page.cpp
index 29e3ff8..7e9b6d1 100644
--- a/src/lua/modules/graphics/je_lua_page.cpp
+++ b/src/lua/modules/graphics/je_lua_page.cpp
@@ -57,16 +57,15 @@ namespace JinEngine
return 1;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getSize", l_getSize },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_Page(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getSize", l_getSize },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { 0, 0 }
+ };
luax_newtype(L, JIN_GRAPHICS_PAGE, f);
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_shader.cpp b/src/lua/modules/graphics/je_lua_shader.cpp
index 9913bc3..cab31cf 100644
--- a/src/lua/modules/graphics/je_lua_shader.cpp
+++ b/src/lua/modules/graphics/je_lua_shader.cpp
@@ -111,23 +111,22 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "sendNumber", l_sendNumber },
- { "sendTexture", l_sendTexture },
- { "sendCanvas", l_sendCanvas },
- { "sendVec2", l_sendVec2 },
- { "sendVec3", l_sendVec3 },
- { "sendVec4", l_sendVec4 },
- { "sendColor", l_sendColor },
- { 0, 0 }
- };
-
/**
* JSL program
*/
LUA_EXPORT int luaopen_JSL(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "sendNumber", l_sendNumber },
+ { "sendTexture", l_sendTexture },
+ { "sendCanvas", l_sendCanvas },
+ { "sendVec2", l_sendVec2 },
+ { "sendVec3", l_sendVec3 },
+ { "sendVec4", l_sendVec4 },
+ { "sendColor", l_sendColor },
+ { 0, 0 }
+ };
luax_newtype(L, JIN_GRAPHICS_SHADER, f);
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_text.cpp b/src/lua/modules/graphics/je_lua_text.cpp
index 60ab28c..4d6db5f 100644
--- a/src/lua/modules/graphics/je_lua_text.cpp
+++ b/src/lua/modules/graphics/je_lua_text.cpp
@@ -17,13 +17,12 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "__gc", l_gc },
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_Text(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { 0, 0 }
+ };
luax_newtype(L, JIN_GRAPHICS_TEXT, f);
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_texture.cpp b/src/lua/modules/graphics/je_lua_texture.cpp
index 5236438..d7571b6 100644
--- a/src/lua/modules/graphics/je_lua_texture.cpp
+++ b/src/lua/modules/graphics/je_lua_texture.cpp
@@ -46,17 +46,16 @@ namespace JinEngine
proxy->release();
return 0;
}
-
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { 0, 0 }
- };
-
+
LUA_EXPORT int luaopen_Texture(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { 0, 0 }
+ };
luax_newtype(L, JIN_GRAPHICS_TEXTURE, f);
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp
index dbaa997..1cdbfff 100644
--- a/src/lua/modules/graphics/je_lua_texture_font.cpp
+++ b/src/lua/modules/graphics/je_lua_texture_font.cpp
@@ -51,16 +51,15 @@ namespace JinEngine
return 1;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "typeset", l_typeset },
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_TextureFont(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { 0, 0 }
+ };
luax_newtype(L, JIN_GRAPHICS_TEXTUREFONT, f);
-
+
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp
index 3e6050b..4e47906 100644
--- a/src/lua/modules/graphics/je_lua_ttf.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf.cpp
@@ -57,14 +57,13 @@ namespace JinEngine
return 1;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "typeset", l_typeset },
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_TTF(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { 0, 0 }
+ };
luax_newtype(L, JIN_GRAPHICS_TTF, f);
return 0;
diff --git a/src/lua/modules/graphics/je_lua_ttf_data.cpp b/src/lua/modules/graphics/je_lua_ttf_data.cpp
index e46fca6..cc91d60 100644
--- a/src/lua/modules/graphics/je_lua_ttf_data.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf_data.cpp
@@ -36,15 +36,15 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "newTTF", l_newTTF },
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_TTFData(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "newTTF", l_newTTF },
+ { 0, 0 }
+ };
luax_newtype(L, JIN_GRAPHICS_TTFDATA, f);
+
return 0;
}
diff --git a/src/lua/modules/joypad/je_lua_joypad.cpp b/src/lua/modules/joypad/je_lua_joypad.cpp
index 5972f40..a57fc99 100644
--- a/src/lua/modules/joypad/je_lua_joypad.cpp
+++ b/src/lua/modules/joypad/je_lua_joypad.cpp
@@ -7,12 +7,11 @@ namespace JinEngine
namespace Lua
{
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_joypad(lua_State* L)
{
+ luaL_Reg f[] = {
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/math/je_lua_math.cpp b/src/lua/modules/math/je_lua_math.cpp
index fd8ffa5..2afeaf9 100644
--- a/src/lua/modules/math/je_lua_math.cpp
+++ b/src/lua/modules/math/je_lua_math.cpp
@@ -16,13 +16,12 @@ namespace JinEngine
return 1;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "mod", l_mod },
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_math(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "mod", l_mod },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
}
diff --git a/src/lua/modules/mouse/je_lua_mouse.cpp b/src/lua/modules/mouse/je_lua_mouse.cpp
index d6c84e7..9e6824a 100644
--- a/src/lua/modules/mouse/je_lua_mouse.cpp
+++ b/src/lua/modules/mouse/je_lua_mouse.cpp
@@ -26,15 +26,14 @@ namespace JinEngine
mouse->setVisible(visible);
return 0;
}
-
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "getPosition", l_pos },
- { "setVisible", l_setVisible },
- { 0, 0 }
- };
LUA_EXPORT int luaopen_mouse(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "getPosition", l_pos },
+ { "setVisible", l_setVisible },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
}
diff --git a/src/lua/modules/net/je_lua_buffer.cpp b/src/lua/modules/net/je_lua_buffer.cpp
index 974c935..751de05 100644
--- a/src/lua/modules/net/je_lua_buffer.cpp
+++ b/src/lua/modules/net/je_lua_buffer.cpp
@@ -8,117 +8,116 @@ namespace JinEngine
{
namespace Lua
{
- namespace Net
- {
+ typedef Shared<Net::Buffer>& SharedBuffer;
- typedef Shared<Buffer>& SharedBuffer;
+ static inline SharedBuffer checkNetBuffer(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER);
+ return proxy->getShared<Net::Buffer>();
+ }
- static inline SharedBuffer checkNetBuffer(lua_State* L)
+ // net.Buffer:append(value) -> value_length
+ LUA_IMPLEMENT int l_append(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ const int vp = 2;
+ if (luax_isintegerstrict(L, vp))
{
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER);
- return proxy->getShared<Buffer>();
- }
-
- // net.Buffer:append(value) -> value_length
- LUA_IMPLEMENT int l_append(lua_State* L)
+ int n = luax_checkinteger(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else if (luax_isfloatstrict(L, vp))
{
- SharedBuffer shared = checkNetBuffer(L);
- const int vp = 2;
- if (luax_isintegerstrict(L, vp))
- {
- int n = luax_checkinteger(L, vp);
- int size = sizeof(n);
- shared->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isfloatstrict(L, vp))
- {
- float n = luax_checknumber(L, vp);
- int size = sizeof(n);
- shared->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isbooleanstrict(L, vp))
- {
- bool n = luax_checkbool(L, vp);
- int size = sizeof(n);
- shared->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isstringstrict(L, vp))
- {
- const char* str = luax_checkstring(L, vp);
- int size = strlen(str) + 1;
- shared->append(str, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else
- {
- luax_typerror(L, vp, "number, bool or string");
- return 0;
- }
+ float n = luax_checknumber(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
}
-
- // net.Buffer:grabString(offset) -> string, length
- LUA_IMPLEMENT int l_grabString(lua_State* L)
+ else if (luax_isbooleanstrict(L, vp))
{
- SharedBuffer shared = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- unsigned int len;
- char* data = shared->grabString(&len, offset);
- Array<char> str;
- str.bind(data, len);
- luax_pushstring(L, &str);
- luax_pushinteger(L, str.count());
- return 2;
+ bool n = luax_checkbool(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
}
-
- // net.Buffer:grabInteger(offset) -> integer, length
- LUA_IMPLEMENT int l_grabInteger(lua_State* L)
+ else if (luax_isstringstrict(L, vp))
{
- SharedBuffer shared = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- int integer = shared->grabInteger(&len, offset);
- luax_pushinteger(L, integer);
- luax_pushinteger(L, len);
- return 2;
+ const char* str = luax_checkstring(L, vp);
+ int size = strlen(str) + 1;
+ shared->append(str, size);
+ luax_pushinteger(L, size);
+ return 1;
}
-
- LUA_IMPLEMENT int l_grabFloat(lua_State* L)
+ else
{
- SharedBuffer shared = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- float floatv = shared->grabFloat(&len, offset);
- luax_pushnumber(L, floatv);
- luax_pushinteger(L, len);
- return 2;
+ luax_typerror(L, vp, "number, bool or string");
+ return 0;
}
+ }
- LUA_IMPLEMENT int l_grabBoolean(lua_State* L)
- {
- SharedBuffer shared = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- bool boolean = shared->grabBoolean(&len, offset);
- luax_pushboolean(L, boolean);
- luax_pushinteger(L, len);
- return 2;
- }
+ // net.Buffer:grabString(offset) -> string, length
+ LUA_IMPLEMENT int l_grabString(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ unsigned int len;
+ char* data = shared->grabString(&len, offset);
+ Array<char> str;
+ str.bind(data, len);
+ luax_pushstring(L, &str);
+ luax_pushinteger(L, str.count());
+ return 2;
+ }
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER);
- proxy->release();
- return 0;
- }
+ // net.Buffer:grabInteger(offset) -> integer, length
+ LUA_IMPLEMENT int l_grabInteger(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ int integer = shared->grabInteger(&len, offset);
+ luax_pushinteger(L, integer);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_grabFloat(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ float floatv = shared->grabFloat(&len, offset);
+ luax_pushnumber(L, floatv);
+ luax_pushinteger(L, len);
+ return 2;
+ }
- LUA_IMPLEMENT const luaL_Reg netbuffer_function[] = {
+ LUA_IMPLEMENT int l_grabBoolean(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ bool boolean = shared->grabBoolean(&len, offset);
+ luax_pushboolean(L, boolean);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_Buffer(lua_State* L)
+ {
+ luaL_Reg netbuffer_function[] = {
{ "__gc", l_gc },
{ "append", l_append },
{ "grabString", l_grabString },
@@ -128,11 +127,7 @@ namespace JinEngine
{ 0, 0 }
};
- } // namespace Net
-
- LUA_EXPORT int luaopen_Buffer(lua_State* L)
- {
- luax_newtype(L, JIN_NETWORK_BUFFER, Net::netbuffer_function);
+ luax_newtype(L, JIN_NETWORK_BUFFER, netbuffer_function);
return 0;
}
diff --git a/src/lua/modules/net/je_lua_net.cpp b/src/lua/modules/net/je_lua_net.cpp
index 58ece43..4240903 100644
--- a/src/lua/modules/net/je_lua_net.cpp
+++ b/src/lua/modules/net/je_lua_net.cpp
@@ -62,13 +62,6 @@ namespace Lua
return 1;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "init", l_initNetwork },
- { "newSocket", l_Socket },
- { "newBuffer", l_Buffer },
- { 0, 0 }
- };
-
LUA_PORT int luaopen_Socket(lua_State* L);
LUA_PORT int luaopen_Buffer(lua_State* L);
@@ -76,7 +69,13 @@ namespace Lua
{
luaopen_Socket(L);
luaopen_Buffer(L);
-
+
+ luaL_Reg f[] = {
+ { "init", l_initNetwork },
+ { "newSocket", l_Socket },
+ { "newBuffer", l_Buffer },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/net/je_lua_socket.cpp b/src/lua/modules/net/je_lua_socket.cpp
index 4072921..a51f5f3 100644
--- a/src/lua/modules/net/je_lua_socket.cpp
+++ b/src/lua/modules/net/je_lua_socket.cpp
@@ -107,20 +107,19 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT const luaL_Reg socket_function[] = {
- { "__gc", l_gc },
- { "accept", l_accept },
- { "receive", l_receive },
- { "receiveFrom", l_receiveFrom },
- { "send", l_send },
- { "sendTo", l_sendTo },
- { "close", l_close },
- { "configBlocking", l_configBlocking },
- { 0, 0 }
- };
-
LUA_EXPORT int 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_NETWORK_SOCKET, socket_function);
return 0;
}
diff --git a/src/lua/modules/thread/je_lua_thread.cpp b/src/lua/modules/thread/je_lua_thread.cpp
index 8b8d1d5..290de6e 100644
--- a/src/lua/modules/thread/je_lua_thread.cpp
+++ b/src/lua/modules/thread/je_lua_thread.cpp
@@ -193,22 +193,22 @@ namespace JinEngine
return 1;
}
- LUA_IMPLEMENT const luaL_Reg thread_function[] = {
- { "__gc", l_thread_gc },
- { "start", l_start },
- { "wait", l_wait },
- { "send", l_send },
- { "receive", l_receive },
- { "fetch", l_fetch },
- { "demand", l_demand },
- { "remove", l_remove },
- { "getName", l_getName },
- { "isRunning", l_isRunning },
- { 0, 0 }
- };
-
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_THREAD_THREAD, thread_function);
return 0;
@@ -231,16 +231,15 @@ namespace JinEngine
return 1;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "newThread", l_newThread },
- { "getThread", l_getThread },
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_thread(lua_State* L)
{
luaopen_Thread(L);
-
+
+ luaL_Reg f[] = {
+ { "newThread", l_newThread },
+ { "getThread", l_getThread },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/time/je_lua_time.cpp b/src/lua/modules/time/je_lua_time.cpp
index e565eab..c42fc0f 100644
--- a/src/lua/modules/time/je_lua_time.cpp
+++ b/src/lua/modules/time/je_lua_time.cpp
@@ -49,22 +49,21 @@ namespace JinEngine
context.current = getSecond();
return 0;
}
-
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "second", l_sec },
- { "sleep", l_sleep },
- { "newTimer", l_newTimer },
- { "step", l_step },
- { "getDelta", l_getDelta },
- { 0, 0 },
- };
LUA_PORT int luaopen_Timer(lua_State* L);
LUA_EXPORT int luaopen_time(lua_State* L)
{
luaopen_Timer(L);
-
+
+ luaL_Reg f[] = {
+ { "second", l_sec },
+ { "sleep", l_sleep },
+ { "newTimer", l_newTimer },
+ { "step", l_step },
+ { "getDelta", l_getDelta },
+ { 0, 0 },
+ };
luax_newlib(L, f);
return 1;
}
diff --git a/src/lua/modules/time/je_lua_timer.cpp b/src/lua/modules/time/je_lua_timer.cpp
index 239d1dd..42d4215 100644
--- a/src/lua/modules/time/je_lua_timer.cpp
+++ b/src/lua/modules/time/je_lua_timer.cpp
@@ -126,19 +126,19 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "every", l_every },
- { "after", l_after },
- { "duplicate", l_repeat },
- { "update", l_update },
- { "cancel", l_cancel },
- { "cancelAll", l_cancelAll },
- { 0, 0 }
- };
-
LUA_EXPORT int luaopen_Timer(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "every", l_every },
+ { "after", l_after },
+ { "duplicate", l_repeat },
+ { "update", l_update },
+ { "cancel", l_cancel },
+ { "cancelAll", l_cancelAll },
+ { 0, 0 }
+ };
+
luax_newtype(L, JIN_TIME_TIMER, f);
return 0;
}