diff options
Diffstat (limited to 'src/libjin-lua/modules/graphics')
31 files changed, 1469 insertions, 1469 deletions
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 |