refactor: LuaState replaced with lua_engine

This commit is contained in:
MihailRis
2024-06-11 13:18:30 +03:00
parent 0647bc6f90
commit 90bc86408b
22 changed files with 643 additions and 675 deletions
+26 -26
View File
@@ -7,7 +7,7 @@
using namespace scripting;
static int l_add_command(lua_State* L) {
if (!lua_isfunction(L, 3)) {
if (!lua::isfunction(L, 3)) {
throw std::runtime_error("invalid callback");
}
auto scheme = lua::require_string(L, 1);
@@ -45,11 +45,11 @@ static int l_get_commands_list(lua_State* L) {
auto repo = interpreter->getRepository();
const auto& commands = repo->getCommands();
lua_createtable(L, commands.size(), 0);
lua::createtable(L, commands.size(), 0);
size_t index = 1;
for (const auto& entry : commands) {
lua_pushstring(L, entry.first.c_str());
lua_rawseti(L, -2, index++);
lua::pushstring(L, entry.first);
lua::rawseti(L, index++);
}
return 1;
}
@@ -65,44 +65,44 @@ static int l_get_command_info(lua_State* L) {
const auto& args = command->getArgs();
const auto& kwargs = command->getKwArgs();
lua_createtable(L, 0, 4);
lua::createtable(L, 0, 4);
lua_pushstring(L, name);
lua_setfield(L, -2, "name");
lua::pushstring(L, name);
lua::setfield(L, "name");
lua_pushstring(L, command->getDescription().c_str());
lua_setfield(L, -2, "description");
lua::pushstring(L, command->getDescription());
lua::setfield(L, "description");
lua_createtable(L, args.size(), 0);
lua::createtable(L, args.size(), 0);
for (size_t i = 0; i < args.size(); i++) {
auto& arg = args.at(i);
lua_createtable(L, 0, 2);
lua::createtable(L, 0, 2);
lua_pushstring(L, arg.name.c_str());
lua_setfield(L, -2, "name");
lua::pushstring(L, arg.name);
lua::setfield(L, "name");
lua_pushstring(L, cmd::argtype_name(arg.type).c_str());
lua_setfield(L, -2, "type");
lua::pushstring(L, cmd::argtype_name(arg.type));
lua::setfield(L, "type");
if (arg.optional) {
lua_pushboolean(L, true);
lua_setfield(L, -2, "optional");
lua::pushboolean(L, true);
lua::setfield(L, "optional");
}
lua_rawseti(L, -2, i+1);
lua::rawseti(L, i+1);
}
lua_setfield(L, -2, "args");
lua::setfield(L, "args");
lua_createtable(L, 0, kwargs.size());
lua::createtable(L, 0, kwargs.size());
for (auto& entry : kwargs) {
auto& arg = entry.second;
lua_createtable(L, 0, 1);
lua::createtable(L, 0, 1);
lua_pushstring(L, cmd::argtype_name(arg.type).c_str());
lua_setfield(L, -2, "type");
lua_setfield(L, -2, arg.name.c_str());
lua::pushstring(L, cmd::argtype_name(arg.type));
lua::setfield(L, "type");
lua::setfield(L, arg.name);
}
lua_setfield(L, -2, "kwargs");
lua::setfield(L, "kwargs");
return 1;
}