core.get_setting test
This commit is contained in:
parent
75a7b89fc8
commit
f8ec75b121
@ -98,15 +98,15 @@ static Value* value_from_binary(ByteReader& reader) {
|
|||||||
break;
|
break;
|
||||||
case BJSON_TYPE_BYTE:
|
case BJSON_TYPE_BYTE:
|
||||||
type = valtype::integer;
|
type = valtype::integer;
|
||||||
val = reader.get();
|
val = static_cast<integer_t>(reader.get());
|
||||||
break;
|
break;
|
||||||
case BJSON_TYPE_INT16:
|
case BJSON_TYPE_INT16:
|
||||||
type = valtype::integer;
|
type = valtype::integer;
|
||||||
val = reader.getInt16();
|
val = static_cast<integer_t>(reader.getInt16());
|
||||||
break;
|
break;
|
||||||
case BJSON_TYPE_INT32:
|
case BJSON_TYPE_INT32:
|
||||||
type = valtype::integer;
|
type = valtype::integer;
|
||||||
val = reader.getInt32();
|
val = static_cast<integer_t>(reader.getInt32());
|
||||||
break;
|
break;
|
||||||
case BJSON_TYPE_INT64:
|
case BJSON_TYPE_INT64:
|
||||||
type = valtype::integer;
|
type = valtype::integer;
|
||||||
@ -119,7 +119,7 @@ static Value* value_from_binary(ByteReader& reader) {
|
|||||||
case BJSON_TYPE_FALSE:
|
case BJSON_TYPE_FALSE:
|
||||||
case BJSON_TYPE_TRUE:
|
case BJSON_TYPE_TRUE:
|
||||||
type = valtype::boolean;
|
type = valtype::boolean;
|
||||||
val = typecode - BJSON_TYPE_FALSE;
|
val = (typecode - BJSON_TYPE_FALSE) != 0;
|
||||||
break;
|
break;
|
||||||
case BJSON_TYPE_STRING:
|
case BJSON_TYPE_STRING:
|
||||||
type = valtype::string;
|
type = valtype::string;
|
||||||
|
|||||||
@ -353,7 +353,7 @@ Value::~Value() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Value Value::of(bool value) {
|
Value Value::boolean(bool value) {
|
||||||
return Value(valtype::boolean, value);
|
return Value(valtype::boolean, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ namespace dynamic {
|
|||||||
Value(valtype type, valvalue value);
|
Value(valtype type, valvalue value);
|
||||||
~Value();
|
~Value();
|
||||||
|
|
||||||
static Value of(bool value);
|
static Value boolean(bool value);
|
||||||
static Value of(number_u value);
|
static Value of(number_u value);
|
||||||
static Value of(const std::string& value);
|
static Value of(const std::string& value);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -280,9 +280,9 @@ dynamic::Value lua::LuaState::tovalue(int idx) {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case LUA_TNIL:
|
case LUA_TNIL:
|
||||||
case LUA_TNONE:
|
case LUA_TNONE:
|
||||||
return dynamic::Value(valtype::none, 0);
|
return dynamic::Value(valtype::none, (integer_t)0);
|
||||||
case LUA_TBOOLEAN:
|
case LUA_TBOOLEAN:
|
||||||
return dynamic::Value::of(lua_toboolean(L, idx) == 1);
|
return dynamic::Value::boolean(lua_toboolean(L, idx) == 1);
|
||||||
case LUA_TNUMBER: {
|
case LUA_TNUMBER: {
|
||||||
auto number = lua_tonumber(L, idx);
|
auto number = lua_tonumber(L, idx);
|
||||||
auto integer = lua_tointeger(L, idx);
|
auto integer = lua_tointeger(L, idx);
|
||||||
|
|||||||
@ -13,6 +13,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
namespace scripting {
|
||||||
|
extern lua::LuaState* state;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_get_worlds_list(lua_State* L) {
|
static int l_get_worlds_list(lua_State* L) {
|
||||||
auto paths = scripting::engine->getPaths();
|
auto paths = scripting::engine->getPaths();
|
||||||
auto worlds = paths->scanForWorlds();
|
auto worlds = paths->scanForWorlds();
|
||||||
@ -66,6 +70,13 @@ static int l_get_bindings(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_get_setting(lua_State* L) {
|
||||||
|
auto name = lua_tostring(L, 1);
|
||||||
|
const auto value = scripting::engine->getSettingsHandler().getValue(name);
|
||||||
|
scripting::state->pushvalue(value);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_quit(lua_State* L) {
|
static int l_quit(lua_State* L) {
|
||||||
Window::setShouldClose(true);
|
Window::setShouldClose(true);
|
||||||
return 0;
|
return 0;
|
||||||
@ -77,6 +88,7 @@ const luaL_Reg corelib [] = {
|
|||||||
{"close_world", lua_wrap_errors<l_close_world>},
|
{"close_world", lua_wrap_errors<l_close_world>},
|
||||||
{"delete_world", lua_wrap_errors<l_delete_world>},
|
{"delete_world", lua_wrap_errors<l_delete_world>},
|
||||||
{"get_bindings", lua_wrap_errors<l_get_bindings>},
|
{"get_bindings", lua_wrap_errors<l_get_bindings>},
|
||||||
|
{"get_setting", lua_wrap_errors<l_get_setting>},
|
||||||
{"quit", lua_wrap_errors<l_quit>},
|
{"quit", lua_wrap_errors<l_quit>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user