Merge branch 'main' into update-gfx-pipeline
This commit is contained in:
commit
54655543bb
@ -25,3 +25,6 @@ end
|
||||
print(#arr, arr:get_capacity())
|
||||
arr:trim()
|
||||
assert(#arr == arr:get_capacity())
|
||||
|
||||
arr = Bytearray({0, 2, 7, 1, 16, 75, 25})
|
||||
assert(arr[6] == 75)
|
||||
|
||||
@ -179,7 +179,7 @@ local FFIBytearray = {
|
||||
return bytearray_type(buffer, #n, #n)
|
||||
elseif t == "table" then
|
||||
local capacity = math.max(#n, MIN_CAPACITY)
|
||||
local buffer = malloc(capacity)
|
||||
local buffer = FFI.cast("unsigned char*", malloc(capacity))
|
||||
for i=1,#n do
|
||||
buffer[i - 1] = n[i]
|
||||
end
|
||||
|
||||
@ -239,13 +239,52 @@ dv::value toml::parse(std::string_view file, std::string_view source) {
|
||||
return TomlReader(file, source).read();
|
||||
}
|
||||
|
||||
static void to_string(std::stringstream& ss, const dv::value& value);
|
||||
|
||||
static void list_to_string(std::stringstream& ss, const dv::value& list) {
|
||||
ss << "[";
|
||||
int index = 0;
|
||||
for (const auto& value : list) {
|
||||
if (index > 0) {
|
||||
ss << ", ";
|
||||
}
|
||||
to_string(ss, value);
|
||||
index++;
|
||||
}
|
||||
ss << "]";
|
||||
}
|
||||
|
||||
static void object_to_string(std::stringstream& ss, const dv::value& object) {
|
||||
ss << "{";
|
||||
int index = 0;
|
||||
for (const auto& [key, value] : object.asObject()) {
|
||||
if (index > 0) {
|
||||
ss << ", ";
|
||||
}
|
||||
ss << key << " = ";
|
||||
to_string(ss, value);
|
||||
index++;
|
||||
}
|
||||
ss << "}";
|
||||
}
|
||||
|
||||
static void to_string(std::stringstream& ss, const dv::value& value) {
|
||||
if (value.isObject()) {
|
||||
object_to_string(ss, value);
|
||||
} else if (value.isList()) {
|
||||
list_to_string(ss, value);
|
||||
} else {
|
||||
ss << value;
|
||||
}
|
||||
}
|
||||
|
||||
std::string toml::stringify(const dv::value& root, const std::string& name) {
|
||||
std::stringstream ss;
|
||||
if (!name.empty()) {
|
||||
ss << "[" << name << "]\n";
|
||||
}
|
||||
for (const auto& [key, value] : root.asObject()) {
|
||||
if (!value.isObject()) {
|
||||
if (!value.isObject() && !value.isList()) {
|
||||
ss << key << " = " << value << "\n";
|
||||
}
|
||||
}
|
||||
@ -253,6 +292,15 @@ std::string toml::stringify(const dv::value& root, const std::string& name) {
|
||||
if (value.isObject()) {
|
||||
ss << "\n" << toml::stringify(value,
|
||||
name.empty() ? key : name + "." + key);
|
||||
} else if (value.isList()) {
|
||||
ss << (name.empty() ? key : name + "." + key) << " = [";
|
||||
for (size_t i = 0; i < value.size(); i++) {
|
||||
if (i > 0) {
|
||||
ss << ", ";
|
||||
}
|
||||
to_string(ss, value[i]);
|
||||
}
|
||||
ss << "]";
|
||||
}
|
||||
}
|
||||
return ss.str();
|
||||
|
||||
@ -232,9 +232,9 @@ static int l_set_data(lua::State* L, ItemStack& stack) {
|
||||
}
|
||||
|
||||
const luaL_Reg inventorylib[] = {
|
||||
{"get", wrap_slot<l_get>},
|
||||
{"set", wrap_slot<l_set>},
|
||||
{"set_count", wrap_slot<l_set_count>},
|
||||
{"get", lua::wrap<wrap_slot<l_get>>},
|
||||
{"set", lua::wrap<wrap_slot<l_set>>},
|
||||
{"set_count", lua::wrap<wrap_slot<l_set_count>>},
|
||||
{"size", lua::wrap<l_size>},
|
||||
{"add", lua::wrap<l_add>},
|
||||
{"move", lua::wrap<l_move>},
|
||||
@ -243,10 +243,10 @@ const luaL_Reg inventorylib[] = {
|
||||
{"get_block", lua::wrap<l_get_block>},
|
||||
{"bind_block", lua::wrap<l_bind_block>},
|
||||
{"unbind_block", lua::wrap<l_unbind_block>},
|
||||
{"get_data", wrap_slot<l_get_data>},
|
||||
{"set_data", wrap_slot<l_set_data>},
|
||||
{"get_all_data", wrap_slot<l_get_all_data>},
|
||||
{"has_data", wrap_slot<l_has_data>},
|
||||
{"get_data", lua::wrap<wrap_slot<l_get_data>>},
|
||||
{"set_data", lua::wrap<wrap_slot<l_set_data>>},
|
||||
{"get_all_data", lua::wrap<wrap_slot<l_get_all_data>>},
|
||||
{"has_data", lua::wrap<wrap_slot<l_has_data>>},
|
||||
{"create", lua::wrap<l_create>},
|
||||
{"remove", lua::wrap<l_remove>},
|
||||
{"clone", lua::wrap<l_clone>},
|
||||
|
||||
@ -23,4 +23,5 @@ static int l_toml_parse(lua::State* L) {
|
||||
const luaL_Reg tomllib[] = {
|
||||
{"tostring", lua::wrap<l_toml_stringify>},
|
||||
{"parse", lua::wrap<l_toml_parse>},
|
||||
{NULL, NULL}};
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -14,6 +14,7 @@ public:
|
||||
|
||||
ObserverHandler(ObserverHandler&& handler) noexcept
|
||||
: destructor(std::move(handler.destructor)) {
|
||||
handler.destructor = nullptr;
|
||||
}
|
||||
|
||||
~ObserverHandler() {
|
||||
@ -33,6 +34,7 @@ public:
|
||||
destructor();
|
||||
}
|
||||
destructor = std::move(handler.destructor);
|
||||
handler.destructor = nullptr;
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
|
||||
@ -228,7 +228,7 @@ public:
|
||||
callbacks->second.notify();
|
||||
}
|
||||
}
|
||||
if (pressed) {
|
||||
if (pressed && key < MOUSE_KEYS_OFFSET) {
|
||||
pressedKeys.push_back(static_cast<Keycode>(key));
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,6 +26,9 @@ TEST(TOML, EncodeDecode) {
|
||||
object["score"] = score;
|
||||
object["visible"] = visible;
|
||||
object["data"] = srcBytes;
|
||||
object["values"] = dv::list({
|
||||
5, 3, std::string("hello"), dv::object({{"number", 1234}})
|
||||
});
|
||||
|
||||
text = toml::stringify(object, "");
|
||||
std::cout << text << std::endl;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user