fix: lua coroutines support
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "api_lua.hpp"
|
||||
#include "lua_commons.hpp"
|
||||
#include "lua_util.hpp"
|
||||
#include "LuaState.hpp"
|
||||
|
||||
#include "../scripting.hpp"
|
||||
@@ -17,10 +18,10 @@ static int l_add_command(lua_State* L) {
|
||||
if (!lua_isfunction(L, 3)) {
|
||||
throw std::runtime_error("invalid callback");
|
||||
}
|
||||
auto scheme = state->requireString(1);
|
||||
auto description = state->requireString(2);
|
||||
auto scheme = lua::require_string(L, 1);
|
||||
auto description = lua::require_string(L, 2);
|
||||
lua_pushvalue(L, 3);
|
||||
auto func = state->createLambda();
|
||||
auto func = state->createLambda(L);
|
||||
try {
|
||||
engine->getCommandsInterpreter()->getRepository()->add(
|
||||
scheme, description, [func](auto, auto args, auto kwargs) {
|
||||
@@ -33,16 +34,16 @@ static int l_add_command(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_execute(lua_State*) {
|
||||
auto prompt = state->requireString(1);
|
||||
static int l_execute(lua_State* L) {
|
||||
auto prompt = lua::require_string(L, 1);
|
||||
auto result = engine->getCommandsInterpreter()->execute(prompt);
|
||||
state->pushvalue(result);
|
||||
lua::pushvalue(L, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_set(lua_State*) {
|
||||
auto name = state->requireString(1);
|
||||
auto value = state->tovalue(2);
|
||||
static int l_set(lua_State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto value = lua::tovalue(L, 2);
|
||||
(*engine->getCommandsInterpreter())[name] = value;
|
||||
return 0;
|
||||
}
|
||||
@@ -62,7 +63,7 @@ static int l_get_commands_list(lua_State* L) {
|
||||
}
|
||||
|
||||
static int l_get_command_info(lua_State* L) {
|
||||
auto name = state->requireString(1);
|
||||
auto name = lua::require_string(L, 1);
|
||||
auto interpreter = engine->getCommandsInterpreter();
|
||||
auto repo = interpreter->getRepository();
|
||||
auto command = repo->get(name);
|
||||
|
||||
Reference in New Issue
Block a user