From 2c97dada7b9c7fedc511f1ecf012346c198d92f8 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 11 Aug 2018 08:17:13 -0400 Subject: Various updates Edit boxes can have their contents retreived Fixed a typo for edit box methods various updates to the net api --- src/shared/lua_api/load_net.cpp | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'src/shared/lua_api/load_net.cpp') 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::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} }; -- cgit v1.2.3-70-g09d2