diff options
Diffstat (limited to 'src/lua/modules/graphics/graphics.cpp')
-rw-r--r-- | src/lua/modules/graphics/graphics.cpp | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp index 4ef2b56..31f6fba 100644 --- a/src/lua/modules/graphics/graphics.cpp +++ b/src/lua/modules/graphics/graphics.cpp @@ -1,18 +1,16 @@ -#include "lua/modules/luax.h" -#include "lua/modules/types.h" -#include "libjin/jin.h" -#include "lua/common/common.h" - #include <iostream> #include <fstream> -using namespace std; +#include "libjin/jin.h" +#include "lua/modules/luax.h" +#include "lua/modules/types.h" +#include "lua/common/common.h" namespace jin { namespace lua { - + using namespace std; using namespace jin::graphics; using jin::filesystem::Filesystem; using jin::filesystem::Buffer; @@ -655,8 +653,23 @@ namespace lua { Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP); Bitmap* bitmap = p->getObject<Bitmap>(); - Proxy* pt = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT); - Text* text = pt->getObject<Text>(); + Text* text; + if (luax_istype(L, 2, JIN_GRAPHICS_TEXT)) + { + Proxy* pt = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT); + text = pt->getObject<Text>(); + } + else if (luax_isstring(L, 2)) + { + unsigned len; + const char* str = luax_checklstring(L, 2, &len); + text = new Text(Encode::UTF8, str, len); + } + else + { + luax_typerror(L, 2, "Text or string"); + return 1; + } float cellh = luax_checknumber(L, 4); TextureFont* textureFont = nullptr; if (luax_istable(L, 3)) @@ -672,6 +685,16 @@ namespace lua float cellw = luax_checknumber(L, 3); textureFont = TextureFont::createTextureFont(bitmap, *text, cellw, cellh); } + else + { + luax_error(L, "bad arguments #3 to 'newTextureFont', need to be table or number"); + return 0; + } + if (luax_isstring(L, 2)) + { + // Delete temporary text. + delete text; + } Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTUREFONT, sizeof(Proxy)); proxy->bind(new Ref<TextureFont>(textureFont, JIN_GRAPHICS_TEXTUREFONT)); return 1; |