commands results and variables
This commit is contained in:
@@ -154,8 +154,8 @@ void lua::LuaState::loadbuffer(int env, const std::string& src, const std::strin
|
||||
}
|
||||
}
|
||||
|
||||
int lua::LuaState::call(int argc) {
|
||||
if (lua_pcall(L, argc, LUA_MULTRET, 0)) {
|
||||
int lua::LuaState::call(int argc, int nresults) {
|
||||
if (lua_pcall(L, argc, nresults, 0)) {
|
||||
throw lua::luaerror(lua_tostring(L, -1));
|
||||
}
|
||||
return 1;
|
||||
@@ -416,7 +416,7 @@ scripting::common_func lua::LuaState::createLambda() {
|
||||
for (const auto& arg : args) {
|
||||
pushvalue(arg);
|
||||
}
|
||||
if (call(args.size())) {
|
||||
if (call(args.size(), 1)) {
|
||||
auto result = tovalue(-1);
|
||||
pop(1);
|
||||
return result;
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace lua {
|
||||
const char* tostring(int idx);
|
||||
bool isstring(int idx);
|
||||
bool isfunction(int idx);
|
||||
int call(int argc);
|
||||
int call(int argc, int nresults=-1);
|
||||
int callNoThrow(int argc);
|
||||
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>");
|
||||
|
||||
@@ -36,8 +36,16 @@ static int l_execute(lua_State* L) {
|
||||
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 [] = {
|
||||
{"add_command", lua_wrap_errors<l_add_command>},
|
||||
{"execute", lua_wrap_errors<l_execute>},
|
||||
{"set", lua_wrap_errors<l_set>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user