diff options
| author | Alexander Pickering <alex@cogarr.net> | 2018-08-31 21:46:18 -0400 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2018-08-31 21:46:18 -0400 |
| commit | b3c0d2ead1f384b35615be562c5f06804e8990cb (patch) | |
| tree | 5310a73eea21890d33a9d64d77bee0361201c207 /src/client/lua_api/gui/iguibutton.cpp | |
| parent | 92940a587d3db28f95a7e2ddf72cbbe7f110e107 (diff) | |
| download | brokengine-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/iguibutton.cpp')
| -rw-r--r-- | src/client/lua_api/gui/iguibutton.cpp | 12 |
1 files changed, 5 insertions, 7 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; } |
