diff --git a/examples/proto_debuger/lua_wraper.h b/examples/proto_debuger/lua_wraper.h index f4f71184..cf9374f8 100644 --- a/examples/proto_debuger/lua_wraper.h +++ b/examples/proto_debuger/lua_wraper.h @@ -27,70 +27,87 @@ public: int UpdateScript(std::string); - void pushstack(lua_Number arg) { + int pushstack(lua_Number arg) { lua_pushnumber(mVM, arg); + return 1; } - void pushstack(lua_Integer arg) { + int pushstack(lua_Integer arg) { lua_pushinteger(mVM, arg); + return 1; } - void pushstack(void* arg) { + int pushstack(void* arg) { lua_pushlightuserdata(mVM, arg); + return 1; } - void pushstack(const char* arg) { + int pushstack(const char* arg) { lua_pushstring(mVM,arg); + return 1; } - void pushstack(bool arg) { + int pushstack(bool arg) { lua_pushboolean (mVM, arg); + return 1; } - void pushstack(std::string arg) { + int pushstack(std::string arg) { lua_pushstring(mVM, arg.c_str()); + return 1; } - void pushstack(lua_CFunction fn, int n) { + int pushstack(lua_CFunction fn, int n) { lua_pushcclosure(mVM, fn, n); + return 1; } template - void pushstack(lua_Number arg1, Types... rest) { + int pushstack(lua_Number arg1, Types... rest) { lua_pushnumber(mVM, arg1); - pushstack(rest...); + int ret = pushstack(rest...) + 1; + return ret; } template - void pushstack(lua_Integer arg1, Types... rest) { + int pushstack(lua_Integer arg1, Types... rest) { lua_pushinteger (mVM, arg1); - pushstack(rest...); + int ret = pushstack(rest...) + 1; + return ret; } template - void pushstack(bool arg1, Types... rest) { + int pushstack(bool arg1, Types... rest) { lua_pushboolean(mVM, arg1); - pushstack(rest...); + int ret = pushstack(rest...) + 1; + return ret; } template - void pushstack(std::string arg1, Types... rest) { + int pushstack(std::string arg1, Types... rest) { lua_pushstring(mVM, arg1.c_str()); - pushstack(rest...); + int ret = pushstack(rest...) + 1; + return ret; } template - void pushstack(void* arg1, Types... rest) { + int pushstack(void* arg1, Types... rest) { lua_pushlightuserdata(mVM, arg1); - pushstack(rest...); + int ret = pushstack(rest...) + 1; + return ret; } template - void pushstack(lua_CFunction fn, int n, Types... rest) { + int pushstack(lua_CFunction fn, int n, Types... rest) { lua_pushcclosure(mVM, fn,n); - pushstack(rest...); + int ret = pushstack(rest...) + 1; + return ret; } template - void pushstack(const char* arg1, Types... rest) { + int pushstack(const char* arg1, Types... rest) { lua_pushstring(mVM, arg1); - pushstack(rest...); + int ret = pushstack(rest...) + 1; + return ret; } template - void CallFuntion(std::string name,T... para){ + int CallFuntion(std::string name,T... para){ int i = lua_getglobal(mVM,name.c_str()); - if(i < 0){ - return ; + if(LUA_TNIL == i){ + return -1; } - pushstack(para...); + int ret = pushstack(para...); + std::cout << "parameter count is " << ret; + lua_call(mVM, ret, 0); + return 0; } lua_State* VM(); void PrintError(lua_State *L); diff --git a/examples/proto_debuger/main.cpp b/examples/proto_debuger/main.cpp index b880712a..55397cc4 100644 --- a/examples/proto_debuger/main.cpp +++ b/examples/proto_debuger/main.cpp @@ -57,8 +57,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, LuaDelegate lua; std::cout << std::endl; - lua.CallFuntion< lua_Number>(std::string("sds"), - 123.0); +// lua.CallFuntion< lua_Number>(std::string("sds"), +// 123.0); UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); diff --git a/examples/proto_debuger/uart_form.cpp b/examples/proto_debuger/uart_form.cpp index 01f40f83..ddc8b878 100644 --- a/examples/proto_debuger/uart_form.cpp +++ b/examples/proto_debuger/uart_form.cpp @@ -48,7 +48,7 @@ UartForm::UartForm(ui::Window* hwnd,std::wstring name, if (0 < SerialPort::ReadPort(PortNum, recv, 1024)) { printf("recv data: %s", recv); this->m_show_recv += string2wstring(recv); - this->mLua->OnSerialData(recv); + this->mLua->CallFuntion("OnUartData", std::string(recv)); if (this->mEditRecv != nullptr) { this->mEditRecv->AppendText(string2wstring(recv), false); ::PostMessage(this->GetWindow()->GetHWND(), WM_ADD_UART_RECVDATA,0, 0);