diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/audio/luaopen_Source.cpp | 18 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_Canvas.cpp | 10 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_Font.cpp | 2 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_Image.cpp | 12 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_JSL.cpp | 14 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_graphics.cpp | 8 | ||||
-rw-r--r-- | src/lua/luaopen_types.h | 19 | ||||
-rw-r--r-- | src/lua/net/luaopen_Buffer.cpp | 16 | ||||
-rw-r--r-- | src/lua/net/luaopen_Socket.cpp | 27 | ||||
-rw-r--r-- | src/lua/thread/luaopen_Thread.cpp | 28 | ||||
-rw-r--r-- | src/lua/thread/luaopen_thread.cpp | 28 |
11 files changed, 90 insertions, 92 deletions
diff --git a/src/lua/audio/luaopen_Source.cpp b/src/lua/audio/luaopen_Source.cpp index b5db88f..25e44b3 100644 --- a/src/lua/audio/luaopen_Source.cpp +++ b/src/lua/audio/luaopen_Source.cpp @@ -18,42 +18,42 @@ namespace lua static int l_play(lua_State* L) { Ref<Source>& ref = checkSource(L); - (*ref).play(); + ref->play(); return 0; } static int l_stop(lua_State* L) { Ref<Source>& ref = checkSource(L); - (*ref).stop(); + ref->stop(); return 0; } static int l_pause(lua_State* L) { Ref<Source>& ref = checkSource(L); - (*ref).pause(); + ref->pause(); return 0; } static int l_rewind(lua_State* L) { Ref<Source>& ref = checkSource(L); - (*ref).rewind(); + ref->rewind(); return 0; } static int l_resume(lua_State* L) { Ref<Source>& ref = checkSource(L); - (*ref).resume(); + ref->resume(); return 0; } static int l_isStop(lua_State* L) { Ref<Source>& ref = checkSource(L); - bool isStop = (*ref).isStopped(); + bool isStop = ref->isStopped(); luax_pushboolean(L, isStop); return 1; } @@ -61,7 +61,7 @@ namespace lua static int l_isPaused(lua_State* L) { Ref<Source>& ref = checkSource(L); - bool isPaused = (*ref).isPaused(); + bool isPaused = ref->isPaused(); luax_pushboolean(L, isPaused); return 1; } @@ -70,7 +70,7 @@ namespace lua { Ref<Source>& ref = checkSource(L); float volume = luax_checknumber(L, 2); - (*ref).setVolume(volume); + ref->setVolume(volume); return 0; } @@ -78,7 +78,7 @@ namespace lua { Ref<Source>& ref = checkSource(L); bool loop = luax_checkbool(L, 2); - (*ref).setLoop(loop); + ref->setLoop(loop); return 0; } diff --git a/src/lua/graphics/luaopen_Canvas.cpp b/src/lua/graphics/luaopen_Canvas.cpp index d686a88..ca1270c 100644 --- a/src/lua/graphics/luaopen_Canvas.cpp +++ b/src/lua/graphics/luaopen_Canvas.cpp @@ -18,22 +18,22 @@ namespace lua static int l_getWidth(lua_State* L) { Ref<Canvas>& ref = checkCanvas(L); - luax_pushnumber(L, (*ref).getWidth()); + luax_pushnumber(L, ref->getWidth()); return 1; } static int l_getHeight(lua_State* L) { Ref<Canvas>& ref = checkCanvas(L); - luax_pushnumber(L, (*ref).getHeight()); + luax_pushnumber(L, ref->getHeight()); return 1; } static int l_getSize(lua_State* L) { Ref<Canvas>& ref = checkCanvas(L); - luax_pushnumber(L, (*ref).getWidth()); - luax_pushnumber(L, (*ref).getHeight()); + luax_pushnumber(L, ref->getWidth()); + luax_pushnumber(L, ref->getHeight()); return 2; } @@ -42,7 +42,7 @@ namespace lua Ref<Canvas>& ref = checkCanvas(L); int x = luax_checknumber(L, 1); int y = luax_checknumber(L, 2); - (*ref).setAnchor(x, y); + ref->setAnchor(x, y); return 0; } diff --git a/src/lua/graphics/luaopen_Font.cpp b/src/lua/graphics/luaopen_Font.cpp index 341af87..dc891b0 100644 --- a/src/lua/graphics/luaopen_Font.cpp +++ b/src/lua/graphics/luaopen_Font.cpp @@ -25,7 +25,7 @@ namespace lua int spacing = luax_checknumber(L, 4); int lheight = luax_checknumber(L, 5); int w, h; - (*ref).box(text, fheight, lheight, spacing, &w, &h); + ref->box(text, fheight, lheight, spacing, &w, &h); luax_pushnumber(L, w); luax_pushnumber(L, h); return 2; diff --git a/src/lua/graphics/luaopen_Image.cpp b/src/lua/graphics/luaopen_Image.cpp index b1672d5..47cb4c6 100644 --- a/src/lua/graphics/luaopen_Image.cpp +++ b/src/lua/graphics/luaopen_Image.cpp @@ -20,14 +20,14 @@ namespace lua static int l_getWidth(lua_State* L) { Ref<Image>& ref = checkImage(L); - luax_pushnumber(L, (*ref).getWidth()); + luax_pushnumber(L, ref->getWidth()); return 1; } static int l_getHeight(lua_State *L) { Ref<Image>& ref = checkImage(L); - luax_pushnumber(L, (*ref).getHeight()); + luax_pushnumber(L, ref->getHeight()); return 1; } @@ -36,7 +36,7 @@ namespace lua Ref<Image>& ref = checkImage(L); int x = luax_checknumber(L, 2); int y = luax_checknumber(L, 3); - color c = (*ref).getPixel(x, y); + color c = ref->getPixel(x, y); luax_pushnumber(L, c.rgba.r); luax_pushnumber(L, c.rgba.g); luax_pushnumber(L, c.rgba.b); @@ -49,15 +49,15 @@ namespace lua Ref<Image>& ref = checkImage(L); int x = luax_checknumber(L, 2); int y = luax_checknumber(L, 3); - (*ref).setAnchor(x, y); + ref->setAnchor(x, y); return 0; } static int l_getSize(lua_State* L) { Ref<Image>& ref = checkImage(L); - luax_pushnumber(L, (*ref).getWidth()); - luax_pushnumber(L, (*ref).getHeight()); + luax_pushnumber(L, ref->getWidth()); + luax_pushnumber(L, ref->getHeight()); return 2; } diff --git a/src/lua/graphics/luaopen_JSL.cpp b/src/lua/graphics/luaopen_JSL.cpp index e644c35..30b109a 100644 --- a/src/lua/graphics/luaopen_JSL.cpp +++ b/src/lua/graphics/luaopen_JSL.cpp @@ -61,28 +61,28 @@ namespace lua case NUMBER: { float number = luax_checknumber(L, 4); - (*ref).sendFloat(variable, number); + ref->sendFloat(variable, number); break; } case IMAGE: { Proxy* proxy = (Proxy*)luax_checktype(L, 4, JIN_GRAPHICS_IMAGE); Ref<Image>& tex = proxy->getRef<Image>(); - (*ref).sendTexture(variable, &(*tex)); + ref->sendTexture(variable, tex.getObject()); break; } case CANVAS: { Proxy* proxy = (Proxy*)luax_checktype(L, 4, JIN_GRAPHICS_CANVAS); Ref<Canvas>& canvas = proxy->getRef<Canvas>(); - (*ref).sendCanvas(variable, &(*canvas)); + ref->sendCanvas(variable, canvas.getObject()); break; } case VEC2: { float x = luax_checknumber(L, 4); float y = luax_checknumber(L, 5); - (*ref).sendVec2(variable, x, y); + ref->sendVec2(variable, x, y); break; } case VEC3: @@ -90,7 +90,7 @@ namespace lua float x = luax_checknumber(L, 4); float y = luax_checknumber(L, 5); float z = luax_checknumber(L, 6); - (*ref).sendVec3(variable, x, y, z); + ref->sendVec3(variable, x, y, z); break; } case VEC4: @@ -99,7 +99,7 @@ namespace lua float y = luax_checknumber(L, 5); float z = luax_checknumber(L, 6); float w = luax_checknumber(L, 7); - (*ref).sendVec4(variable, x, y, z, w); + ref->sendVec4(variable, x, y, z, w); break; } case COLOR: @@ -109,7 +109,7 @@ namespace lua col.rgba.g = luax_checkinteger(L, 5); col.rgba.b = luax_checkinteger(L, 6); col.rgba.a = luax_checkinteger(L, 7); - (*ref).sendColor(variable, &col); + ref->sendColor(variable, &col); break; } default: diff --git a/src/lua/graphics/luaopen_graphics.cpp b/src/lua/graphics/luaopen_graphics.cpp index dc8c9a1..14449a4 100644 --- a/src/lua/graphics/luaopen_graphics.cpp +++ b/src/lua/graphics/luaopen_graphics.cpp @@ -152,13 +152,13 @@ namespace lua if (luax_istype(L, 1, JIN_GRAPHICS_IMAGE)) { Proxy* proxy = (Proxy*)luax_toudata(L, 1); - Image* tex = &*proxy->getRef<Image>(); + Ref<Image>& tex = proxy->getRef<Image>(); tex->draw(x, y, sx, sy, r); } else if (luax_istype(L, 1, JIN_GRAPHICS_CANVAS)) { Proxy* proxy = (Proxy*)luax_toudata(L, 1); - Canvas* p = &*proxy->getRef<Canvas>(); + Ref<Canvas>& p = proxy->getRef<Canvas>(); p->draw(x, y, sx, sy, r); } else @@ -210,7 +210,7 @@ namespace lua } Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS); Ref<Canvas>& ref = proxy->getRef<Canvas>(); - (*ref).bind(); + ref->bind(); return 0; } @@ -230,7 +230,7 @@ namespace lua if (luax_istype(L, 1, JIN_GRAPHICS_SHADER)) { Proxy* proxy = (Proxy*)luax_toudata(L, 1); - JSLProgram* jsl = &*proxy->getRef<JSLProgram>(); + Ref<JSLProgram>& jsl = proxy->getRef<JSLProgram>(); jsl->use(); } else diff --git a/src/lua/luaopen_types.h b/src/lua/luaopen_types.h index be59157..78083c6 100644 --- a/src/lua/luaopen_types.h +++ b/src/lua/luaopen_types.h @@ -64,11 +64,14 @@ namespace lua T* obj = (T*)object; delete obj; } - T& operator *() - { - T* obj = (T*)object; - return *obj; - } + T* operator->() + { + return (T*)object; + } + T* getObject() + { + return (T*)object; + } private: Ref(const Ref<T>& ref); }; @@ -97,12 +100,12 @@ namespace lua template<class T> Ref<T>& getRef() { - Ref<T>* ref = (Ref<T>*) reference; - return *ref; + return *(Ref<T>*) reference; } - Reference* reference; // acctual object binded const char* type; // type name and metatable name + Reference* reference; // acctual object binded + }; } // lua diff --git a/src/lua/net/luaopen_Buffer.cpp b/src/lua/net/luaopen_Buffer.cpp index e7100cc..f50f82e 100644 --- a/src/lua/net/luaopen_Buffer.cpp +++ b/src/lua/net/luaopen_Buffer.cpp @@ -25,7 +25,7 @@ namespace net { int n = luax_checkinteger(L, vp); int size = sizeof(n); - (*ref).append(&n, size); + ref->append(&n, size); luax_pushinteger(L, size); return 1; } @@ -33,7 +33,7 @@ namespace net { float n = luax_checknumber(L, vp); int size = sizeof(n); - (*ref).append(&n, size); + ref->append(&n, size); luax_pushinteger(L, size); return 1; } @@ -41,7 +41,7 @@ namespace net { bool n = luax_checkbool(L, vp); int size = sizeof(n); - (*ref).append(&n, size); + ref->append(&n, size); luax_pushinteger(L, size); return 1; } @@ -49,7 +49,7 @@ namespace net { const char* str = luax_checkstring(L, vp); int size = strlen(str) + 1; - (*ref).append(str, size); + ref->append(str, size); luax_pushinteger(L, size); return 1; } @@ -66,7 +66,7 @@ namespace net Ref<Buffer>& ref = checkNetBuffer(L); int offset = luax_checkinteger(L, 2); int len; - const char* str = (*ref).grabString(&len, offset); + const char* str = ref->grabString(&len, offset); luax_pushstring(L, str); luax_pushinteger(L, len); return 2; @@ -78,7 +78,7 @@ namespace net Ref<Buffer>& ref = checkNetBuffer(L); int offset = luax_checkinteger(L, 2); int len; - int integer = (*ref).grabInteger(&len, offset); + int integer = ref->grabInteger(&len, offset); luax_pushinteger(L, integer); luax_pushinteger(L, len); return 2; @@ -89,7 +89,7 @@ namespace net Ref<Buffer>& ref = checkNetBuffer(L); int offset = luax_checkinteger(L, 2); int len; - float floatv = (*ref).grabFloat(&len, offset); + float floatv = ref->grabFloat(&len, offset); luax_pushnumber(L, floatv); luax_pushinteger(L, len); return 2; @@ -100,7 +100,7 @@ namespace net Ref<Buffer>& ref = checkNetBuffer(L); int offset = luax_checkinteger(L, 2); int len; - bool boolean = (*ref).grabBoolean(&len, offset); + bool boolean = ref->grabBoolean(&len, offset); luax_pushboolean(L, boolean); luax_pushinteger(L, len); return 2; diff --git a/src/lua/net/luaopen_Socket.cpp b/src/lua/net/luaopen_Socket.cpp index 40a62b6..4f8c45a 100644 --- a/src/lua/net/luaopen_Socket.cpp +++ b/src/lua/net/luaopen_Socket.cpp @@ -29,10 +29,9 @@ namespace lua static int l_accept(lua_State* L) { Ref<Socket>& socket = checkSocket(L); - Socket* client = (*socket).accept(); - Ref<Socket>* ref = new Ref<Socket>(client); + Socket* client = socket->accept(); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy)); - proxy->bind(ref, JIN_NETWORK_SOCKET); + proxy->bind(new Ref<Socket>(client), JIN_NETWORK_SOCKET); return 1; } @@ -41,11 +40,10 @@ namespace lua { Ref<Socket>& socket = checkSocket(L); char buffer[BUFFER_SIZE] = {0}; - int size = (*socket).receive(buffer, BUFFER_SIZE); + int size = socket->receive(buffer, BUFFER_SIZE); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy)); net::Buffer* netBuffer = new net::Buffer(buffer, size); - Ref<Buffer>* ref = new Ref<Buffer>(netBuffer); - proxy->bind(ref, JIN_NETWORK_BUFFER); + proxy->bind(new Ref<Buffer>(netBuffer), JIN_NETWORK_BUFFER); return 1; } @@ -56,11 +54,10 @@ namespace lua 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); + int size = socket->receiveFrom(buffer, BUFFER_SIZE, address, port); net::Buffer* netBuffer = new net::Buffer(buffer, size); - Ref<Buffer>* ref = new Ref<Buffer>(netBuffer); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy)); - proxy->bind(ref, JIN_NETWORK_BUFFER); + proxy->bind(new Ref<Buffer>(netBuffer), JIN_NETWORK_BUFFER); return 1; } @@ -69,8 +66,7 @@ namespace lua { Ref<Socket>& socket = checkSocket(L); Ref<Buffer>& ref = checkNetBuffer(L, 2); - net::Buffer* buffer = &*ref; - int len = (*socket).send(buffer->buffer, buffer->size); + int len = socket->send(ref->buffer, ref->size); luax_pushinteger(L, len); return 1; } @@ -81,16 +77,15 @@ namespace lua Ref<Socket>& socket = checkSocket(L); int address = luax_checkinteger(L, 2); int port = luax_checkinteger(L, 3); - Ref<Buffer>& ref = checkNetBuffer(L, 4); - net::Buffer* buffer = &*ref; - (*socket).sendTo(buffer->buffer, buffer->size, address, port); + Ref<Buffer>& buffer = checkNetBuffer(L, 4); + socket->sendTo(buffer->buffer, buffer->size, address, port); return 0; } static int l_close(lua_State* L) { Ref<Socket>& socket = checkSocket(L); - (*socket).close(); + socket->close(); return 0; } @@ -98,7 +93,7 @@ namespace lua { Ref<Socket>& socket = checkSocket(L); bool blocking = luax_checkbool(L, 2); - (*socket).configureBlocking(blocking); + socket->configureBlocking(blocking); return 0; } diff --git a/src/lua/thread/luaopen_Thread.cpp b/src/lua/thread/luaopen_Thread.cpp index 2b4d01d..0d87907 100644 --- a/src/lua/thread/luaopen_Thread.cpp +++ b/src/lua/thread/luaopen_Thread.cpp @@ -30,7 +30,7 @@ namespace lua ref.retain(); proxy->bind(&ref, JIN_THREAD_THREAD); luax_setfield(L, -2, "_curThread"); - luax_dostring(L, (*ref).code.c_str()); + luax_dostring(L, ref->code.c_str()); luax_close(L); return 0; } @@ -45,7 +45,7 @@ namespace lua static int l_start(lua_State* L) { Ref<Thread>& ref = checkThread(L); - bool result = (*ref).start(&ref); + bool result = ref->start(&ref); luax_pushboolean(L, result); return 1; } @@ -53,7 +53,7 @@ namespace lua static int l_wait(lua_State* L) { Ref<Thread>& ref = checkThread(L); - (*ref).wait(); + ref->wait(); return 0; } @@ -65,27 +65,27 @@ namespace lua if (luax_isnumberstrict(L, vp)) { float real = luax_checknumber(L, vp); - (*ref).send(slot, real); + ref->send(slot, real); } else if (luax_isbooleanstrict(L, vp)) { bool bol = luax_checkbool(L, vp); - (*ref).send(slot, bol); + ref->send(slot, bol); } else if (luax_isstringstrict(L, vp)) { const char* str = luax_checkstring(L, vp); - (*ref).send(slot, str); + ref->send(slot, str); } else if (luax_isuserdata(L, vp)) { void* p = luax_touserdata(L, vp); - (*ref).send(slot, p); + ref->send(slot, p); } else if (luax_islightuserdata(L, vp)) { void* p = luax_tolightuserdata(L, vp); - (*ref).send(slot, p); + ref->send(slot, p); } return 0; } @@ -94,7 +94,7 @@ namespace lua { Ref<Thread>& ref = checkThread(L); int slot = luax_checkinteger(L, 2); - bool result = (*ref).receive(slot); + bool result = ref->receive(slot); luax_pushboolean(L, result); return 1; } @@ -103,7 +103,7 @@ namespace lua { Ref<Thread>& ref = checkThread(L); int slot = luax_checkinteger(L, 2); - Thread::Variant v = (*ref).fetch(slot); + Thread::Variant v = ref->fetch(slot); switch (v.type) { case thread::Thread::Variant::INTERGER: @@ -137,7 +137,7 @@ namespace lua { Ref<Thread>& ref = checkThread(L); int slot = luax_checkinteger(L, 2); - Thread::Variant v = (*ref).demand(slot); + Thread::Variant v = ref->demand(slot); switch (v.type) { case thread::Thread::Variant::INTERGER: @@ -171,14 +171,14 @@ namespace lua { Ref<Thread>& ref = checkThread(L); int slot = luax_checkinteger(L, 2); - (*ref).remove(slot); + ref->remove(slot); return 0; } static int l_getName(lua_State* L) { Ref<Thread>& ref = checkThread(L); - const char* name = (*ref).getName(); + const char* name = ref->getName(); luax_pushstring(L, name); return 1; } @@ -186,7 +186,7 @@ namespace lua static int l_isRunning(lua_State* L) { Ref<Thread>& ref = checkThread(L); - bool running = (*ref).isRunning(); + bool running = ref->isRunning(); luax_pushboolean(L, running); return 1; } diff --git a/src/lua/thread/luaopen_thread.cpp b/src/lua/thread/luaopen_thread.cpp index 2b4d01d..0d87907 100644 --- a/src/lua/thread/luaopen_thread.cpp +++ b/src/lua/thread/luaopen_thread.cpp @@ -30,7 +30,7 @@ namespace lua ref.retain(); proxy->bind(&ref, JIN_THREAD_THREAD); luax_setfield(L, -2, "_curThread"); - luax_dostring(L, (*ref).code.c_str()); + luax_dostring(L, ref->code.c_str()); luax_close(L); return 0; } @@ -45,7 +45,7 @@ namespace lua static int l_start(lua_State* L) { Ref<Thread>& ref = checkThread(L); - bool result = (*ref).start(&ref); + bool result = ref->start(&ref); luax_pushboolean(L, result); return 1; } @@ -53,7 +53,7 @@ namespace lua static int l_wait(lua_State* L) { Ref<Thread>& ref = checkThread(L); - (*ref).wait(); + ref->wait(); return 0; } @@ -65,27 +65,27 @@ namespace lua if (luax_isnumberstrict(L, vp)) { float real = luax_checknumber(L, vp); - (*ref).send(slot, real); + ref->send(slot, real); } else if (luax_isbooleanstrict(L, vp)) { bool bol = luax_checkbool(L, vp); - (*ref).send(slot, bol); + ref->send(slot, bol); } else if (luax_isstringstrict(L, vp)) { const char* str = luax_checkstring(L, vp); - (*ref).send(slot, str); + ref->send(slot, str); } else if (luax_isuserdata(L, vp)) { void* p = luax_touserdata(L, vp); - (*ref).send(slot, p); + ref->send(slot, p); } else if (luax_islightuserdata(L, vp)) { void* p = luax_tolightuserdata(L, vp); - (*ref).send(slot, p); + ref->send(slot, p); } return 0; } @@ -94,7 +94,7 @@ namespace lua { Ref<Thread>& ref = checkThread(L); int slot = luax_checkinteger(L, 2); - bool result = (*ref).receive(slot); + bool result = ref->receive(slot); luax_pushboolean(L, result); return 1; } @@ -103,7 +103,7 @@ namespace lua { Ref<Thread>& ref = checkThread(L); int slot = luax_checkinteger(L, 2); - Thread::Variant v = (*ref).fetch(slot); + Thread::Variant v = ref->fetch(slot); switch (v.type) { case thread::Thread::Variant::INTERGER: @@ -137,7 +137,7 @@ namespace lua { Ref<Thread>& ref = checkThread(L); int slot = luax_checkinteger(L, 2); - Thread::Variant v = (*ref).demand(slot); + Thread::Variant v = ref->demand(slot); switch (v.type) { case thread::Thread::Variant::INTERGER: @@ -171,14 +171,14 @@ namespace lua { Ref<Thread>& ref = checkThread(L); int slot = luax_checkinteger(L, 2); - (*ref).remove(slot); + ref->remove(slot); return 0; } static int l_getName(lua_State* L) { Ref<Thread>& ref = checkThread(L); - const char* name = (*ref).getName(); + const char* name = ref->getName(); luax_pushstring(L, name); return 1; } @@ -186,7 +186,7 @@ namespace lua static int l_isRunning(lua_State* L) { Ref<Thread>& ref = checkThread(L); - bool running = (*ref).isRunning(); + bool running = ref->isRunning(); luax_pushboolean(L, running); return 1; } |