]> git.lizzy.rs Git - minetest.git/commitdiff
Add VoxelArea() constructor (#12886)
authorJude Melton-Houghton <jwmhjwmh@gmail.com>
Sat, 22 Oct 2022 12:05:45 +0000 (08:05 -0400)
committerGitHub <noreply@github.com>
Sat, 22 Oct 2022 12:05:45 +0000 (08:05 -0400)
builtin/game/voxelarea.lua
doc/lua_api.txt

index 62f07d928f9021eb9717c015d62ec43b4ce20d29..a9195213bdbd3ea74a8b7e385027d2a3de7831e8 100644 (file)
@@ -8,7 +8,10 @@ VoxelArea = {
        zstride = 0,
 }
 
-function VoxelArea:new(o)
+local class_metatable = {}
+setmetatable(VoxelArea, class_metatable)
+
+local function new(self, o)
        o = o or {}
        setmetatable(o, self)
        self.__index = self
@@ -20,6 +23,12 @@ function VoxelArea:new(o)
        return o
 end
 
+function class_metatable:__call(MinEdge, MaxEdge)
+       return new(self, {MinEdge = MinEdge, MaxEdge = MaxEdge})
+end
+
+VoxelArea.new = new
+
 function VoxelArea:getExtent()
        local MaxEdge, MinEdge = self.MaxEdge, self.MinEdge
        return vector_new(
index 4e3d1230cc942ded812208d6427891ee043fc379..fd4e2d3e5af94f27658440a575de36a38d8d435a 100644 (file)
@@ -4485,7 +4485,8 @@ Methods
 -----------
 
 A helper class for voxel areas.
-It can be created via `VoxelArea:new({MinEdge = pmin, MaxEdge = pmax})`.
+It can be created via `VoxelArea(pmin, pmax)` or
+`VoxelArea:new({MinEdge = pmin, MaxEdge = pmax})`.
 The coordinates are *inclusive*, like most other things in Minetest.
 
 ### Methods
@@ -4533,7 +4534,7 @@ the axes in a voxel area:
 
 If, for example:
 
-    local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
+    local area = VoxelArea(emin, emax)
 
 The values of `ystride` and `zstride` can be obtained using `area.ystride` and
 `area.zstride`.