commands results and variables
This commit is contained in:
parent
0a45987811
commit
5b2b89c778
@ -1,3 +1,5 @@
|
|||||||
<container size='400' color='#00000080' size-func="unpack(gui.get_viewport())">
|
<container size='400' color='#00000080' size-func="unpack(gui.get_viewport())">
|
||||||
<textbox id='prompt' margin='0' gravity='bottom-left' size-func="gui.get_viewport()[1],40"></textbox>
|
<textbox id='log' margin='0' multiline='true' size-func="gui.get_viewport()[1],gui.get_viewport()[2]-40">
|
||||||
|
</textbox>
|
||||||
|
<textbox id='prompt' consumer='submit' margin='0' gravity='bottom-left' size-func="gui.get_viewport()[1],40"></textbox>
|
||||||
</container>
|
</container>
|
||||||
|
|||||||
@ -1,3 +1,15 @@
|
|||||||
|
function submit(text)
|
||||||
|
local x,y,z = player.get_pos(0)
|
||||||
|
console.set('pos.x', x)
|
||||||
|
console.set('pos.y', y)
|
||||||
|
console.set('pos.z', z)
|
||||||
|
local status, result = pcall(function() return console.execute(text) end)
|
||||||
|
if result ~= nil then
|
||||||
|
document.log.text = document.log.text..tostring(result)..'\n'
|
||||||
|
end
|
||||||
|
document.prompt.text = ""
|
||||||
|
end
|
||||||
|
|
||||||
function on_open()
|
function on_open()
|
||||||
document.prompt.focused = true
|
document.prompt.focused = true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -229,7 +229,10 @@ public:
|
|||||||
case ArgType::integer:
|
case ArgType::integer:
|
||||||
return typeCheck<integer_t>(arg, value, "integer");
|
return typeCheck<integer_t>(arg, value, "integer");
|
||||||
case ArgType::string:
|
case ArgType::string:
|
||||||
return typeCheck<std::string>(arg, value, "string");
|
if (!std::holds_alternative<std::string>(value)) {
|
||||||
|
return !arg->optional;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -316,6 +319,11 @@ public:
|
|||||||
|
|
||||||
if (hasNext() && peekNoJump() != ' ') {
|
if (hasNext() && peekNoJump() != ' ') {
|
||||||
value = parseValue();
|
value = parseValue();
|
||||||
|
if (auto string = std::get_if<std::string>(&value)) {
|
||||||
|
if ((*string)[0] == '$') {
|
||||||
|
value = (*interpreter)[string->substr(1)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// keyword argument
|
// keyword argument
|
||||||
if (!relative && hasNext() && peek() == '=') {
|
if (!relative && hasNext() && peek() == '=') {
|
||||||
@ -328,10 +336,9 @@ public:
|
|||||||
Argument* arg = nullptr;
|
Argument* arg = nullptr;
|
||||||
do {
|
do {
|
||||||
if (arg) {
|
if (arg) {
|
||||||
std::cout << "skipped arg " << arg->name << std::endl;
|
|
||||||
if (auto string = std::get_if<std::string>(&arg->def)) {
|
if (auto string = std::get_if<std::string>(&arg->def)) {
|
||||||
if ((*string)[0] == '$') {
|
if ((*string)[0] == '$') {
|
||||||
args->put((*interpreter)[*string]);
|
args->put((*interpreter)[string->substr(1)]);
|
||||||
} else {
|
} else {
|
||||||
args->put(arg->def);
|
args->put(arg->def);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,6 +93,8 @@ namespace cmd {
|
|||||||
public:
|
public:
|
||||||
CommandsInterpreter() : repository(std::make_unique<CommandsRepository>()) {}
|
CommandsInterpreter() : repository(std::make_unique<CommandsRepository>()) {}
|
||||||
|
|
||||||
|
CommandsInterpreter(const CommandsInterpreter&) = delete;
|
||||||
|
|
||||||
CommandsInterpreter(std::unique_ptr<CommandsRepository> repository)
|
CommandsInterpreter(std::unique_ptr<CommandsRepository> repository)
|
||||||
: repository(std::move(repository)){}
|
: repository(std::move(repository)){}
|
||||||
|
|
||||||
|
|||||||
@ -154,8 +154,8 @@ void lua::LuaState::loadbuffer(int env, const std::string& src, const std::strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua::LuaState::call(int argc) {
|
int lua::LuaState::call(int argc, int nresults) {
|
||||||
if (lua_pcall(L, argc, LUA_MULTRET, 0)) {
|
if (lua_pcall(L, argc, nresults, 0)) {
|
||||||
throw lua::luaerror(lua_tostring(L, -1));
|
throw lua::luaerror(lua_tostring(L, -1));
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -416,7 +416,7 @@ scripting::common_func lua::LuaState::createLambda() {
|
|||||||
for (const auto& arg : args) {
|
for (const auto& arg : args) {
|
||||||
pushvalue(arg);
|
pushvalue(arg);
|
||||||
}
|
}
|
||||||
if (call(args.size())) {
|
if (call(args.size(), 1)) {
|
||||||
auto result = tovalue(-1);
|
auto result = tovalue(-1);
|
||||||
pop(1);
|
pop(1);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -59,7 +59,7 @@ namespace lua {
|
|||||||
const char* tostring(int idx);
|
const char* tostring(int idx);
|
||||||
bool isstring(int idx);
|
bool isstring(int idx);
|
||||||
bool isfunction(int idx);
|
bool isfunction(int idx);
|
||||||
int call(int argc);
|
int call(int argc, int nresults=-1);
|
||||||
int callNoThrow(int argc);
|
int callNoThrow(int argc);
|
||||||
int execute(int env, const std::string& src, const std::string& file="<string>");
|
int execute(int env, const std::string& src, const std::string& file="<string>");
|
||||||
int eval(int env, const std::string& src, const std::string& file="<eval>");
|
int eval(int env, const std::string& src, const std::string& file="<eval>");
|
||||||
|
|||||||
@ -36,8 +36,16 @@ static int l_execute(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_set(lua_State* L) {
|
||||||
|
auto name = lua_tostring(L, 1);
|
||||||
|
auto value = state->tovalue(2);
|
||||||
|
(*engine->getCommandsInterpreter())[name] = value;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg consolelib [] = {
|
const luaL_Reg consolelib [] = {
|
||||||
{"add_command", lua_wrap_errors<l_add_command>},
|
{"add_command", lua_wrap_errors<l_add_command>},
|
||||||
{"execute", lua_wrap_errors<l_execute>},
|
{"execute", lua_wrap_errors<l_execute>},
|
||||||
|
{"set", lua_wrap_errors<l_set>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user