diff options
| author | Alexander Pickering <alex@cogarr.net> | 2018-08-11 08:17:13 -0400 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2018-08-11 08:17:13 -0400 |
| commit | 2c97dada7b9c7fedc511f1ecf012346c198d92f8 (patch) | |
| tree | acc094cc13b21d12385e3f51967bf5b3bdbf42ef | |
| parent | 76b44e3d9b2b9f146866ad66154fecdf3cb8dfd4 (diff) | |
| download | brokengine-2c97dada7b9c7fedc511f1ecf012346c198d92f8.tar.gz brokengine-2c97dada7b9c7fedc511f1ecf012346c198d92f8.tar.bz2 brokengine-2c97dada7b9c7fedc511f1ecf012346c198d92f8.zip | |
Various updates
Edit boxes can have their contents retreived
Fixed a typo for edit box methods
various updates to the net api
| -rw-r--r-- | config.ld | 1 | ||||
| -rw-r--r-- | src/client/callbackhandeler.cpp | 2 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguieditbox.cpp | 14 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguielement.cpp | 27 | ||||
| -rw-r--r-- | src/client/lua_api/gui/iguiwindow.cpp | 4 | ||||
| -rw-r--r-- | src/client/lua_api/load_gui.cpp | 9 | ||||
| -rw-r--r-- | src/client/lua_api/load_video.cpp | 1 | ||||
| -rw-r--r-- | src/client/lua_api/video/iimage.cpp | 2 | ||||
| -rw-r--r-- | src/shared/lua_api/load_net.cpp | 35 | ||||
| -rw-r--r-- | src/shared/lua_api/stream.cpp | 1 | ||||
| -rw-r--r-- | src/shared/lua_api/stream.hpp | 2 |
11 files changed, 92 insertions, 6 deletions
@@ -6,3 +6,4 @@ custom_tags={ "domain", hidden=true, } +merge=true diff --git a/src/client/callbackhandeler.cpp b/src/client/callbackhandeler.cpp index 87a0acf..7584256 100644 --- a/src/client/callbackhandeler.cpp +++ b/src/client/callbackhandeler.cpp @@ -83,7 +83,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){ case EGET_MESSAGEBOX_NO: fieldname = "onNo"; break; case EGET_MESSAGEBOX_OK: fieldname = "onOk"; break; case EGET_MESSAGEBOX_CANCEL: fieldname = "onCancel"; break; - case EGET_EDITBOX_ENTER: fieldname = "onEneter"; break; + case EGET_EDITBOX_ENTER: fieldname = "onEnter"; break; case EGET_EDITBOX_CHANGED: fieldname = "onChange"; break; case EGET_EDITBOX_MARKING_CHANGED: fieldname = "onMarkChange"; break; case EGET_TAB_CHANGED: fieldname = "onTabChange"; break; diff --git a/src/client/lua_api/gui/iguieditbox.cpp b/src/client/lua_api/gui/iguieditbox.cpp index 7b79f34..1ceab1f 100644 --- a/src/client/lua_api/gui/iguieditbox.cpp +++ b/src/client/lua_api/gui/iguieditbox.cpp @@ -61,6 +61,19 @@ static int newiguieditbox(lua_State* L){ return 1; } +//{guieditbox}:getinput() +int getinputtext(lua_State* L){ + lua_getfield(L, -1, "guielement");//{guieditbox},ud_guielement + 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); + lua_pushstring(L,output);//"str" + return 1; +} + static const luaL_reg iguieditbox_f[] = { {"neweditbox",newiguieditbox}, {0,0}, @@ -69,6 +82,7 @@ static const luaL_reg iguieditbox_f[] = { static const luaL_reg iguieditbox_m[] = { {"move", moveiguielement}, {"settext", setiguitext}, + {"getinput", getinputtext}, {"remove", removeiguielement}, {0,0}, }; diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp index fa3d480..5ba998f 100644 --- a/src/client/lua_api/gui/iguielement.cpp +++ b/src/client/lua_api/gui/iguielement.cpp @@ -1,4 +1,9 @@ /*This file defines some things that all igui stuff can do*/ +/*** +@module gui + + +*/ extern "C" { #include <lua.h> #include <lauxlib.h> @@ -15,6 +20,11 @@ using namespace irr; using namespace core; using namespace gui; +/*** +Move a window (by an offset) +@function guielement:move() +@tparam vec2 position The offset to move this element by +*/ //move({element},{x,y}) -> nil int moveiguielement(lua_State* L){ //printf("Got call to move element\n"); @@ -31,6 +41,11 @@ int moveiguielement(lua_State* L){ return 0; } +/*** +Find the rectangle that an element occupies +@function guielement:getabsrect() +@treturn rect The rectangle that this element occupies +*/ //getabsrect({element})-> {{sx,sy},{ex,ey}} int getiguiclippingrect(lua_State* L){ printf("Getting iguiclipping elemnt\n"); @@ -48,6 +63,14 @@ int getiguiclippingrect(lua_State* L){ return 1; } +/*** +Sets the text of the element +This function may do different things to different gui elements. +For example, on a window, it sets the title. +On a button, it sets the button's text. +@function guielement:settext() +@tparam string text The text to set on the element +*/ //setText({guielement},"text") :: nil int setiguitext(lua_State* L){ const char* text = lua_tostring(L, -1); @@ -63,6 +86,10 @@ int setiguitext(lua_State* L){ return 0; } +/*** +Removes a gui element, and any child elements +@function guielement:remove() +*/ //remove({self}) int removeiguielement(lua_State* L){ lua_getfield(L,-1,"guielement"); diff --git a/src/client/lua_api/gui/iguiwindow.cpp b/src/client/lua_api/gui/iguiwindow.cpp index e5c3193..3fbd5e4 100644 --- a/src/client/lua_api/gui/iguiwindow.cpp +++ b/src/client/lua_api/gui/iguiwindow.cpp @@ -76,8 +76,10 @@ static const luaL_reg iguiwindow_m[] = { }; int iguiwindow_register(lua_State* L, IrrlichtDevice* d){ - luaL_newmetatable(L,"gui.window");//m{gui.checkbox} + luaL_newmetatable(L,"gui.window");//m{gui.window} + lua_newtable(L); luaL_register(L,NULL,iguiwindow_m); + lua_setfield(L,-2,"__index"); lua_pop(L,1);// lua_getglobal(L,"gui"); diff --git a/src/client/lua_api/load_gui.cpp b/src/client/lua_api/load_gui.cpp index 4ad5438..5b580bf 100644 --- a/src/client/lua_api/load_gui.cpp +++ b/src/client/lua_api/load_gui.cpp @@ -40,6 +40,15 @@ lua_State* tL; int screenwidth(lua_State* L); int screenheight(lua_State* L); +/*** +@function gui.scrw() +@treturn number The width of the screen +*/ + +/*** +@function gui.scrh() +@treturn number The height of the screen +*/ void load_guifuncs(lua_State* L){ printf("Started loading gui...\n"); tL = L; diff --git a/src/client/lua_api/load_video.cpp b/src/client/lua_api/load_video.cpp index bd07e97..607759c 100644 --- a/src/client/lua_api/load_video.cpp +++ b/src/client/lua_api/load_video.cpp @@ -18,6 +18,7 @@ using namespace core; extern IrrlichtDevice* device; extern IVideoDriver* driver; +//video.drawtexture //{texture},{x,y} //{texture},{x,y},{sourcerect},,{color},use_alpha int draw2dimage(lua_State* L){ diff --git a/src/client/lua_api/video/iimage.cpp b/src/client/lua_api/video/iimage.cpp index 9fb6ec2..1009ea0 100644 --- a/src/client/lua_api/video/iimage.cpp +++ b/src/client/lua_api/video/iimage.cpp @@ -35,7 +35,7 @@ int newiimagefromfile(lua_State* L){ lua_pop(L,1); int numloaders = driver->getImageLoaderCount(); bool hasloaded = false; - IImage* img; + IImage* img = NULL; for(int j = 0; j < numloaders; j++){ IImageLoader* loader = driver->getImageLoader(j); io::IReadFile* f = device->getFileSystem()->createAndOpenFile(strpath); diff --git a/src/shared/lua_api/load_net.cpp b/src/shared/lua_api/load_net.cpp index 48bdc84..cc2db02 100644 --- a/src/shared/lua_api/load_net.cpp +++ b/src/shared/lua_api/load_net.cpp @@ -201,6 +201,29 @@ int lstream_writedouble(lua_State* L){ return 0; } +//stream:getpipe() :: pipe +int lstream_getpipe(lua_State* L){ + lua_getfield(L,-1,"data");//{stream},ud_stream + struct stream* s = (struct stream*)lua_touserdata(L,-1);//{stream},ud_stream + lua_pop(L,2);// + lua_newtable(L);//{} + lua_pushlightuserdata(L,s->pipe);//{},ud_pipe + lua_setfield(L,-2,"pipe");//{pipe} + return 1; +} + +//stream:setpipe(pipe) +int lstream_setpipe(lua_State* L){ + lua_getfield(L,-1,"pipe");//{stream},{pipe},ud_pipe + nng_pipe *pipe = (nng_pipe*)lua_touserdata(L,-1);//{stream},{pipe},ud_pipe + lua_pop(L,2);//{stream} + lua_getfield(L,-1,"data");//{stream},ud_stream + struct stream *s = (struct stream*)lua_touserdata(L,-1); + lua_pop(L,2); + s->pipe = pipe; + return 0; +} + /*** Write some data to the stream @function stream:writedata() @@ -245,9 +268,13 @@ void gameloop_net(lua_State* L){ //printf("Doing net of gameloop\n"); for(std::map<nng_socket*,int>::iterator it = netfuncs.begin(); it != netfuncs.end(); ++it){ //printf("In for socket %d\n"); - char* buf = NULL; - size_t size; - int err = nng_recv(*(it->first), &buf, &size, NNG_FLAG_NONBLOCK | NNG_FLAG_ALLOC); + //char* buf = NULL; + //size_t size; + //int err = nng_recv(*(it->first), &buf, &size, NNG_FLAG_NONBLOCK | NNG_FLAG_ALLOC); + nng_msg *msgp; + int err = nng_recvmsg(*(it->first), &msgp, NNG_FLAG_NONBLOCK); + char* buf = (char*)nng_msg_body(msgp); + size_t size = nng_msg_len(msgp); //printf("Got bytes: %d EAGAIN:%d\n",bytes,EAGAIN); if(err != 0 && err != NNG_EAGAIN){ printf("Net error: %s\n\t err: %d\n\teagain:%d\n",nng_strerror(err),err,NNG_EAGAIN); @@ -467,6 +494,8 @@ static const struct luaL_Reg stream_m[] = { {"readdata",lstream_readdata}, {"readstring",lstream_readstring}, + {"getpipe",lstream_getpipe}, + {"setpipe",lstream_setpipe}, {NULL,NULL} }; diff --git a/src/shared/lua_api/stream.cpp b/src/shared/lua_api/stream.cpp index 9f7200c..fcdc3e3 100644 --- a/src/shared/lua_api/stream.cpp +++ b/src/shared/lua_api/stream.cpp @@ -11,6 +11,7 @@ struct stream* stream_create(){ s->length = 0; s->data = (byte*)malloc(sizeof(byte)*0); s->read = 0; + s->pipe = NULL; return s; } void stream_writeInt(struct stream* s, int number){ diff --git a/src/shared/lua_api/stream.hpp b/src/shared/lua_api/stream.hpp index bf44ed4..74a0e69 100644 --- a/src/shared/lua_api/stream.hpp +++ b/src/shared/lua_api/stream.hpp @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <nng.h> //Char is not definitvely a byte, read the fucking standard #define byte char @@ -7,6 +8,7 @@ typedef struct stream { long length; byte* data; long read; + nng_pipe *pipe; } stream; struct stream* stream_create(); |
