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 /src/shared/lua_api/load_net.cpp | |
| 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
Diffstat (limited to 'src/shared/lua_api/load_net.cpp')
| -rw-r--r-- | src/shared/lua_api/load_net.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
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} }; |
