From 5478f357b62062ffccfecb4c7b5fc607f0e7a518 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 10 Feb 2019 18:10:14 -0500 Subject: Corrected networking examples changed the api for interacting with sockets, sockets now have a callback, `socket:receive(function(stream) ... end)`, which they can use to decide what to do when called. Sockets also have a block:recv() function, which will block EVERYTHING until the socket receives data. This should probably not be used. --- src/client/main.cpp | 56 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 14 deletions(-) (limited to 'src/client/main.cpp') diff --git a/src/client/main.cpp b/src/client/main.cpp index e8533d8..6e515ad 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -109,12 +109,6 @@ void UpdateElement(btRigidBody* TObject){ SColor background = SColor(255,100,101,140); //setbackgroundcolor(r,g,b) -int setbackgroundcolor(lua_State* L){ - long r,g,b; - popvector3i(L,&r,&g,&b); - background = SColor(255,r,g,b); - return 0; -} int main(int argc, char *argv[]){ printf("Brok[en]gine Client\n"); @@ -125,6 +119,7 @@ int main(int argc, char *argv[]){ //Create a new lua state, this gets shared everywhere //Set the path for lua putenv("LUA_PATH=?.lua"); + putenv("LUA_CPATH=../bin/?.dll"); lua_State *state = luaL_newstate(); L = state; printf("Created lua state at %p\n",L); @@ -156,11 +151,29 @@ int main(int argc, char *argv[]){ GlobalEventReceiver ger = GlobalEventReceiver(device); printf("Created event receiver\n"); device->setEventReceiver(&ger); - int iErr = luaL_dofile(state,"init.lua"); - if(iErr != 0){ - printf("Failed to open lua file:%s/init.lua\n",path); - lua_error(state); + + pusherrorfunc(L);//errfunc + switch(luaL_loadfile(state,"init.lua")){//errmsg or nothing + case 0: + break; //no error + case LUA_ERRSYNTAX: + printf("Syntax error, failed to load: %s\n%s","../data/init.lua",lua_tostring(L,-1)); + break; + case LUA_ERRMEM: + printf("Failed to allocate memroy\n"); + break; + case LUA_ERRFILE: + printf("Could not find file: %s\n","../data/init.lua"); + break; } + //errfunc,initfile() + printf("Loaded file\n"); + lua_pcall(state,0,0,-2); + //int iErr = luaL_dofile(state,"init.lua"); + //if(iErr != 0){ + //printf("Failed to open lua file:%s/init.lua\n",path); + //lua_error(state); + //} //Load some bullet physics stuff driver = device->getVideoDriver(); @@ -171,10 +184,9 @@ int main(int argc, char *argv[]){ printf("Everything registered, about to start running device!\n"); - lua_getglobal(L,"GAME"); - lua_pushcfunction(L,setbackgroundcolor); - lua_setfield(L,-2,"setbackgroundcolor"); - lua_pop(L,1); + lua_getglobal(state,"GAME");//{game} + lua_pop(state,1);// + printf("About to check if device run\n"); printf("Device is %p\n",device); while(device->run()){ @@ -197,7 +209,23 @@ int main(int argc, char *argv[]){ } smgr->drawAll(); + lua_getglobal(state,"GAME"); + lua_getfield(state,-1,"drawPostScene"); + if(!lua_isnil(state,-1)){ + lua_call(state,0,0); + lua_pop(state,1); + }else{ + lua_pop(state,2); + } guienv->drawAll(); + lua_getglobal(state,"GAME"); + lua_getfield(state,-1,"drawPostGui"); + if(!lua_isnil(state,-1)){ + lua_call(state,0,0); + lua_pop(state,1); + }else{ + lua_pop(state,2); + } driver->endScene(); }else{ device->yield(); -- cgit v1.2.3-70-g09d2