Suspend then resume Lua from C

  c++, lua, luajit

I’m trying to write a new require function (called "require2" to avoid confusion).

This function should pause (suspend) the Lua state, wait for the server to send the .lua file, and then run the .lua file and continue (resume).

I couldn’t get this to work in Lua 5.1, 5.4.2, or using LuaJit. It always results in the same error: "attempt to yield across a C-call boundary".

When I look up this error, everyone points to LuaJit saying it allows yieldable functions from C, but I can’t get it to work.


int require(lua_State* L)
  std::string fileName = lua_tostring(L, 1);
  Server::getFile(L, fileName); // Send getFile request to server
  return lua_yield(L, 0);

// Assume this is called with the correct lua_State when the file was received from the server
void gotFile(lua_State* L)
  lua_resume(L, 0, 0, 0);


print("Test before require")
print("Test after require")

I’m trying to get only this lua state, which is started in a lua_newthread, to suspend (NOT the entire application) and then resume later.

Why might this not be working?

Source: Windows Questions C++