I have a problem. This takes care of stuff: DWORD WINAPI input(PVOID lvpParameter) {…
- User
I have a problem.
This takes care of stuff: DWORD WINAPI input(PVOID lvpParameter) { std::string WholeScript = ""; HANDLE hPipe; char buffer[999999]; DWORD dwRead;
hPipe = CreateNamedPipe(TEXT("\\\\.\\pipe\\Axon"), PIPE_ACCESS_DUPLEX | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, PIPE_WAIT, 1, sizeof(buffer), sizeof(buffer), NMPWAIT_USE_DEFAULT_WAIT, NULL); if (hPipe == INVALID_HANDLE_VALUE) { printf("WE COULDN'T CREATE AXON PIPE: %ld\n", GetLastError()); return 1; } while (true) { if (ConnectNamedPipe(hPipe, NULL) != FALSE) { while (ReadFile(hPipe, buffer, sizeof(buffer) - 1, &dwRead, NULL) != FALSE && dwRead > 0) { buffer[dwRead] = '\0'; WholeScript += buffer; } try { int lua_thread = lua_newthread(lua_state); // Create a new Lua thread from base state // Load the script into the new Lua thread if (luaL_loadbuffer(lua_thread, WholeScript.c_str(), WholeScript.size(), "script")) { // Compiler error const char* error_message = lua_tolstring(lua_thread, -1, nullptr); printf("compiler error: %s\n", error_message); lua_settop(lua_thread, -1); // Pop the error message } else { // Execute the script if (lua_resume(lua_thread, 0)) { const char* error_message = lua_tolstring(lua_thread, -1, nullptr); if (error_message) { printf("ERROR: %s\n", error_message); } lua_settop(lua_thread, -1); // Pop the error message } } lua_settop(lua_state, 0); // Reset the base state's stack after thread execution } catch (const std::exception& e) { printf("exc: %s\n", e.what()); } catch (...) { printf("no idea what happened here\n"); } WholeScript.clear(); } else { printf("could not connect to pipe: %ld\n", GetLastError()); } DisconnectNamedPipe(hPipe); // Disconnect the pipe after each communication } CloseHandle(hPipe); return 0;}
The execution part has one problem though, if this is executed: wait(5) error("ab")
ERROR: ab WILL NOT BE OUTPUTTED TO THE C++ CONSOLE
Same for this: while wait() do error("abc") end
ERROR: abc WILL NOT BE OUTPUTTED ONCE TO THE C++ CONSOLE (this is a yielding problem)
The functions I have access to are: typedef int(__cdecl* luaL_loadbuffer_t)(int lua_state, const char* buffer, size_t size, const char* chunkname); typedef int(__cdecl* lua_resume_t)(int lua_state, int nargs); typedef int(__cdecl* lua_gettop_t)(int lua_state); typedef int(__cdecl* lua_settop_t)(int lua_state, int idx); typedef int(__cdecl* lua_newthread_t)(int lua_state); typedef const char* (__cdecl* lua_tolstring_t)(int lua_state, int idx, size_t* len);
- Assistant