aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/gui
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2018-08-31 21:46:18 -0400
committerAlexander Pickering <alex@cogarr.net>2018-08-31 21:46:18 -0400
commitb3c0d2ead1f384b35615be562c5f06804e8990cb (patch)
tree5310a73eea21890d33a9d64d77bee0361201c207 /src/client/lua_api/gui
parent92940a587d3db28f95a7e2ddf72cbbe7f110e107 (diff)
downloadbrokengine-b3c0d2ead1f384b35615be562c5f06804e8990cb.tar.gz
brokengine-b3c0d2ead1f384b35615be562c5f06804e8990cb.tar.bz2
brokengine-b3c0d2ead1f384b35615be562c5f06804e8990cb.zip
Fixed wchar_t not being null terminated
Occasionally wierd characters would show in place of a window title or button label, this was due to whcar_t s missing their sentinal characters.
Diffstat (limited to 'src/client/lua_api/gui')
-rw-r--r--src/client/lua_api/gui/iguibutton.cpp12
-rw-r--r--src/client/lua_api/gui/iguielement.cpp8
-rw-r--r--src/client/lua_api/gui/iguifiledialog.cpp10
3 files changed, 13 insertions, 17 deletions
diff --git a/src/client/lua_api/gui/iguibutton.cpp b/src/client/lua_api/gui/iguibutton.cpp
index 5da3773..fa4370f 100644
--- a/src/client/lua_api/gui/iguibutton.cpp
+++ b/src/client/lua_api/gui/iguibutton.cpp
@@ -38,7 +38,7 @@ it is offset from the upper-left of the parent element.
*/
//gui.newbutton({{sx,sy},{ex,ey}},"text"[,parent])
static int newiguibutton(lua_State* L){
- printf("Createing gui button!\n");
+ //printf("Createing gui button!\n");
int nargs = lua_gettop(L);
IGUIElement* parent = NULL;
@@ -49,27 +49,25 @@ static int newiguibutton(lua_State* L){
}
const char* label_c = lua_tostring(L,-1);//{{sx,sy},{ex,ey}},"text"
- const wchar_t* label_w = irr::core::stringw(label_c).c_str();//{{sx,sy},{ex,ey}},"text"
+ size_t label_c_len = strlen(label_c);
+ wchar_t label_w[label_c_len + 1] = L"";
+ mbstowcs(label_w,label_c,label_c_len);
+ label_w[label_c_len] = L'\0';
lua_pop(L,1);//{{sx,sy},{ex,ey}}
- printf("Created title\n");
long sx,sy,ex,ey;
poprecti(L,&sx,&sy,&ex,&ey);//
- printf("Got coords\n");
rect<s32> dim = rect<s32>(sx,sy,ex,ey);
IGUIEnvironment* env = device->getGUIEnvironment();
IGUIButton* but = env->addButton(dim,parent,-1,label_w,L"");
- printf("Added button\n");
lua_newtable(L);//{}
lua_pushlightuserdata(L,but);//{},ud_iguibutton
lua_setfield(L,-2,"guielement");//{guielement}
luaL_getmetatable(L,"gui.iguibutton");//{guielement},{m_iguibutton}
lua_setmetatable(L,-2);//{guielement}
- printf("Created lua representation\n");
setelementcallback(L,EGET_BUTTON_CLICKED,"onClicked");//
- printf("Finished registering callback\n");
return 1;
}
diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp
index e63d986..7132441 100644
--- a/src/client/lua_api/gui/iguielement.cpp
+++ b/src/client/lua_api/gui/iguielement.cpp
@@ -95,9 +95,11 @@ int getiguitext(lua_State* L){
irr::gui::IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1);
lua_pop(L,2);//
const wchar_t *t = el->getText();
- size_t strlen = wcslen(t);
- char output[strlen];
- wcstombs(output,t,strlen);
+ size_t cstrlen = wcslen(t);
+ __mingw_printf("In gui get text, cstrlen is %zu\n",cstrlen);
+ char output[cstrlen + 1];//+1 for \0
+ wcstombs(output,t,cstrlen);
+ output[cstrlen] = '\0';
lua_pushstring(L,output);//"str"
return 1;
}
diff --git a/src/client/lua_api/gui/iguifiledialog.cpp b/src/client/lua_api/gui/iguifiledialog.cpp
index c277ce4..ad95b13 100644
--- a/src/client/lua_api/gui/iguifiledialog.cpp
+++ b/src/client/lua_api/gui/iguifiledialog.cpp
@@ -57,10 +57,6 @@ static int newfileopendialog(lua_State* L){
const char *pathc = lua_tostring(L,-1);//"title","path"
lua_pop(L,1);//"title"
path = (io::path::char_type*)pathc;
- //size_t pathcslen = strlen(pathc);
- //path = (wchar_t*)malloc(sizeof(wchar_t) * (pathcslen + 1));// +1 for null
- //mbstowcs(path,pathc,pathcslen);
- //path[pathcslen] = L'\0';
}
if(nargs > 0){
const char *titlec = lua_tostring(L,-1);
@@ -74,18 +70,18 @@ static int newfileopendialog(lua_State* L){
IGUIEnvironment *env = device->getGUIEnvironment();
IGUIFileOpenDialog *but = env->addFileOpenDialog(title,modal,parent,-1,false,path);
- printf("Added file open dialog\n");
+ //printf("Added file open dialog\n");
lua_newtable(L);//{}
lua_pushlightuserdata(L,but);//{},ud_iguibutton
lua_setfield(L,-2,"guielement");//{guielement}
luaL_getmetatable(L,"gui.iguifileopendialog");//{guielement},{m_iguibutton}
lua_setmetatable(L,-2);//{guielement}
- printf("Created lua representation\n");
+ //printf("Created lua representation\n");
setelementcallback(L,EGET_DIRECTORY_SELECTED,"onDirectory");//
setelementcallback(L,EGET_FILE_SELECTED,"onFileSelected");
setelementcallback(L,EGET_FILE_CHOOSE_DIALOG_CANCELLED,"onCanceled");
- printf("Finished registering callback\n");
+ //printf("Finished registering callback\n");
free(title);
free(path);