update block.get_field, block.set_field and fields-related docs
This commit is contained in:
@@ -372,6 +372,12 @@ void StructLayout::deserialize(const dv::value& src) {
|
||||
|
||||
int elements = 1;
|
||||
fieldmap.at("length").get(elements);
|
||||
if (elements <= 0) {
|
||||
throw std::runtime_error(
|
||||
"invalid field " + util::quote(name) + " length: " +
|
||||
std::to_string(elements)
|
||||
);
|
||||
}
|
||||
|
||||
auto convertStrategy = FieldConvertStrategy::RESET;
|
||||
if (fieldmap.has("convert-strategy")) {
|
||||
|
||||
@@ -489,6 +489,10 @@ static int l_get_field(lua::State* L) {
|
||||
if (field == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
if (index >= field->elements) {
|
||||
throw std::out_of_range(
|
||||
"index out of bounds [0, "+std::to_string(field->elements)+"]");
|
||||
}
|
||||
const ubyte* src = chunk->blocksMetadata.find(voxelIndex);
|
||||
if (src == nullptr) {
|
||||
return 0;
|
||||
@@ -553,6 +557,10 @@ static int l_set_field(lua::State* L) {
|
||||
if (field == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
if (index >= field->elements) {
|
||||
throw std::out_of_range(
|
||||
"index out of bounds [0, "+std::to_string(field->elements)+"]");
|
||||
}
|
||||
ubyte* dst = chunk->blocksMetadata.find(voxelIndex);
|
||||
if (dst == nullptr) {
|
||||
dst = chunk->blocksMetadata.allocate(voxelIndex, dataStruct.size());
|
||||
|
||||
Reference in New Issue
Block a user