CLuaInstCCText: Add various script functions

getLines()
 getLines(test)
 setDimensionsAll(x, y, w, h)

 - Set Lua api version to 1.67


Origin commit data
------------------
Commit: 1576681543
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2016-12-01 (Thu, 01 Dec 2016)
This commit is contained in:
Michael Liebmann
2016-12-01 18:21:47 +01:00
parent b15bec5dd6
commit 23583e07e4
3 changed files with 55 additions and 9 deletions

View File

@@ -4,4 +4,4 @@
* to luainstance.h changes * to luainstance.h changes
*/ */
#define LUA_API_VERSION_MAJOR 1 #define LUA_API_VERSION_MAJOR 1
#define LUA_API_VERSION_MINOR 66 #define LUA_API_VERSION_MINOR 67

View File

@@ -54,14 +54,16 @@ CLuaCCText *CLuaInstCCText::CCTextCheck(lua_State *L, int n)
void CLuaInstCCText::CCTextRegister(lua_State *L) void CLuaInstCCText::CCTextRegister(lua_State *L)
{ {
luaL_Reg meth[] = { luaL_Reg meth[] = {
{ "new", CLuaInstCCText::CCTextNew }, { "new", CLuaInstCCText::CCTextNew },
{ "paint", CLuaInstCCText::CCTextPaint }, { "paint", CLuaInstCCText::CCTextPaint },
{ "hide", CLuaInstCCText::CCTextHide }, { "hide", CLuaInstCCText::CCTextHide },
{ "setText", CLuaInstCCText::CCTextSetText }, { "setText", CLuaInstCCText::CCTextSetText },
{ "scroll", CLuaInstCCText::CCTextScroll }, { "getLines", CLuaInstCCText::CCTextGetLines },
{ "setCenterPos", CLuaInstCCText::CCTextSetCenterPos }, { "scroll", CLuaInstCCText::CCTextScroll },
{ "enableUTF8", CLuaInstCCText::CCTextEnableUTF8 }, { "setCenterPos", CLuaInstCCText::CCTextSetCenterPos },
{ "__gc", CLuaInstCCText::CCTextDelete }, { "enableUTF8", CLuaInstCCText::CCTextEnableUTF8 },
{ "setDimensionsAll", CLuaInstCCText::CCTextSetDimensionsAll },
{ "__gc", CLuaInstCCText::CCTextDelete },
{ NULL, NULL } { NULL, NULL }
}; };
@@ -214,6 +216,26 @@ int CLuaInstCCText::CCTextSetText(lua_State *L)
return 0; return 0;
} }
int CLuaInstCCText::CCTextGetLines(lua_State *L)
{
CLuaCCText *D = CCTextCheck(L, 1);
if (!D) return 0;
lua_Integer lines = 0;
if (lua_gettop(L) == 2) {
const char* Text = luaL_checkstring(L, 2);
lines = (lua_Integer)CTextBox::getLines(Text);
}
else {
CTextBox* ctb = D->ct->getCTextBoxObject();
if (ctb)
lines = (lua_Integer)ctb->getLines();
}
lua_pushinteger(L, lines);
return 1;
}
int CLuaInstCCText::CCTextScroll(lua_State *L) int CLuaInstCCText::CCTextScroll(lua_State *L)
{ {
lua_assert(lua_istable(L,1)); lua_assert(lua_istable(L,1));
@@ -273,6 +295,28 @@ int CLuaInstCCText::CCTextEnableUTF8(lua_State *L)
return 0; return 0;
} }
int CLuaInstCCText::CCTextSetDimensionsAll(lua_State *L)
{
CLuaCCText *D = CCTextCheck(L, 1);
if (!D) return 0;
lua_Integer x = luaL_checkint(L, 2);
lua_Integer y = luaL_checkint(L, 3);
lua_Integer w = luaL_checkint(L, 4);
lua_Integer h = luaL_checkint(L, 5);
if(x>-1 && y > -1 && w > 1 && h > 1){
if (h > (lua_Integer)CFrameBuffer::getInstance()->getScreenHeight())
h = (lua_Integer)CFrameBuffer::getInstance()->getScreenHeight();
if (w > (lua_Integer)CFrameBuffer::getInstance()->getScreenWidth())
w = (lua_Integer)CFrameBuffer::getInstance()->getScreenWidth();
if(x > w)
x = 0;
if(y > h)
y = 0;
D->ct->setDimensionsAll(x,y,w,h);
}
return 0;
}
int CLuaInstCCText::CCTextDelete(lua_State *L) int CLuaInstCCText::CCTextDelete(lua_State *L)
{ {
LUA_DEBUG("CLuaInstCCText::%s %d\n", __func__, lua_gettop(L)); LUA_DEBUG("CLuaInstCCText::%s %d\n", __func__, lua_gettop(L));

View File

@@ -47,9 +47,11 @@ class CLuaInstCCText
static int CCTextPaint(lua_State *L); static int CCTextPaint(lua_State *L);
static int CCTextHide(lua_State *L); static int CCTextHide(lua_State *L);
static int CCTextSetText(lua_State *L); static int CCTextSetText(lua_State *L);
static int CCTextGetLines(lua_State *L);
static int CCTextScroll(lua_State *L); static int CCTextScroll(lua_State *L);
static int CCTextSetCenterPos(lua_State *L); static int CCTextSetCenterPos(lua_State *L);
static int CCTextEnableUTF8(lua_State *L); static int CCTextEnableUTF8(lua_State *L);
static int CCTextSetDimensionsAll(lua_State *L);
static int CCTextDelete(lua_State *L); static int CCTextDelete(lua_State *L);
}; };