forked from gilzoide/godot-lua-pluginscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgodot_pool_vector3_array.lua
More file actions
304 lines (291 loc) · 10.5 KB
/
godot_pool_vector3_array.lua
File metadata and controls
304 lines (291 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
-- @file godot_pool_vector3_array.lua Wrapper for GDNative's PoolVector3Array
-- This file is part of Godot Lua PluginScript: https://github.com/gilzoide/godot-lua-pluginscript
--
-- Copyright (C) 2021 Gil Barbosa Reis.
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the “Software”), to
-- deal in the Software without restriction, including without limitation the
-- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-- sell copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-- IN THE SOFTWARE.
--- PoolVector3Array metatype, wrapper for `godot_pool_vector3_array`
-- @classmod PoolVector3Array
--- PoolVector3Array.Read access metatype, wrapper for `godot_pool_vector3_array_read_access`.
-- @type PoolVector3Array.Read
local Read = ffi_metatype('godot_pool_vector3_array_read_access', {
__index = {
--- Create a copy of Read access.
-- @function Read:copy
-- @treturn Read
copy = function(self)
return ffi_gc(api.godot_pool_vector3_array_read_access_copy(self), self.destroy)
end,
--- Destroy a Read access.
-- Holding a valid access object may lock a PoolVector3Array, so this
-- method should be called manually when access is no longer needed.
-- @function Read:destroy
destroy = function(self)
ffi_gc(self, nil)
api.godot_pool_vector3_array_read_access_destroy(self)
end,
--- Get Read access povector3er.
-- @function Read:ptr
-- @return[type=const Vector3 *]
ptr = api.godot_pool_vector3_array_read_access_ptr,
--- Assign a new Read access.
-- @function Read:assign
-- @tparam Read other
assign = api.godot_pool_vector3_array_read_access_operator_assign,
},
})
--- PoolVector3Array.Write access metatype, wrapper for `godot_pool_vector3_array_write_access`.
-- @type PoolVector3Array.Write
local Write = ffi_metatype('godot_pool_vector3_array_write_access', {
__index = {
--- Create a copy of Write access.
-- @function Write:copy
-- @treturn Write
copy = function(self)
return ffi_gc(api.godot_pool_vector3_array_write_access_copy(self), self.destroy)
end,
--- Destroy a Write access.
-- Holding a valid access object may lock a PoolVector3Array, so this
-- method should be called manually when access is no longer needed.
-- @function Write:destroy
destroy = function(self)
ffi_gc(self, nil)
api.godot_pool_vector3_array_write_access_destroy(self)
end,
--- Get Write access pointer.
-- @function Write:ptr
-- @return[type=Vector3 *]
ptr = api.godot_pool_vector3_array_write_access_ptr,
--- Assign a new Write access.
-- @function Write:assign
-- @tparam Write other
assign = api.godot_pool_vector3_array_write_access_operator_assign,
},
})
--- @type end
local methods = {
fillvariant = api.godot_variant_new_pool_vector3_array,
varianttype = VariantType.PoolVector3Array,
--- Get the vector at `index`.
-- Unlike Lua tables, indices start at 0 instead of 1.
-- For 1-based indexing, use the idiom `array[index]` instead.
--
-- If `index` is invalid (`index < 0` or `index >= size()`), the application will crash.
-- For a safe version that returns `nil` if `index` is invalid, use `safe_get` or the idiom `array[index]` instead.
-- @function get
-- @tparam int index
-- @treturn Vector3
-- @see safe_get
get = api.godot_pool_vector3_array_get,
--- Get the vector at `index`.
-- Unlike Lua tables, indices start at 0 instead of 1.
-- For 1-based indexing, use the idiom `array[index]` instead.
--
-- The idiom `array[index]` also calls this method.
-- @function safe_get
-- @tparam int index
-- @treturn[1] Vector3
-- @treturn[2] nil If index is invalid (`index < 0` or `index >= size()`)
-- @see get
safe_get = array_safe_get,
--- Set a new vector for `index`.
-- Unlike Lua tables, indices start at 0 instead of 1.
-- For 1-based indexing, use the idiom `array[index] = value` instead.
--
-- If `index` is invalid (`index < 0` or `index >= size()`), the application will crash.
-- For a safe approach that `resize`s if `index >= size()`, use `safe_set` or the idiom `array[index] = value` instead.
-- @function set
-- @tparam int index
-- @tparam Vector3 value
-- @see safe_set
set = api.godot_pool_vector3_array_set,
--- Set a new vector for `index`.
-- Unlike Lua tables, indices start at 0 instead of 1.
-- For 1-based indexing, use the idiom `array[index] = value` instead.
--
-- If `index >= size()`, the array is `resize`d first.
-- The idiom `array[index] = value` also calls this method.
-- @function safe_set
-- @tparam int index
-- @tparam Vector3 value
-- @raise If `index < 0`
-- @see set
safe_set = array_safe_set,
--- Inserts a new element at a given position in the array.
-- The position must be valid, or at the end of the array (`index == size()`).
-- @function insert
-- @tparam int index
-- @tparam Vector3 value
insert = api.godot_pool_vector3_array_insert,
--- Reverses the order of the elements in the array.
-- @function invert
invert = api.godot_pool_vector3_array_invert,
--- Append elements at the end of the array.
-- @function push_back
-- @param ... Vectors to be appended
push_back = function(self, ...)
for i = 1, select('#', ...) do
local v = select(i, ...)
api.godot_pool_vector3_array_push_back(self, Vector3(v))
end
end,
--- Removes an element from the array by index.
-- @function remove
-- @tparam int index
remove = api.godot_pool_vector3_array_remove,
--- Sets the size of the array.
-- If the array is grown, reserves elements at the end of the array.
-- If the array is shrunk, truncates the array to the new size.
-- @function resize
-- @tparam int size
resize = api.godot_pool_vector3_array_resize,
--- Returns the size of the array.
-- @function size
-- @treturn int
size = api.godot_pool_vector3_array_size,
--- Returns `true` if the array is empty.
-- @function empty
-- @treturn bool
empty = array_empty,
--- Returns the [Read](#Class_PoolVector3Array_Read) access for the array.
-- @function read
-- @treturn Read
read = function(self)
return ffi_gc(api.godot_pool_vector3_array_read(self), Read.destroy)
end,
--- Returns the [Write](#Class_PoolVector3Array_Write) access for the array.
-- @function write
-- @treturn Write
write = function(self)
return ffi_gc(api.godot_pool_vector3_array_write(self), Write.destroy)
end,
}
--- Alias for `push_back`.
-- @function append
-- @param ...
-- @see push_back
methods.append = methods.push_back
--- Append all vectors of `iterable` at the end of Array.
-- @function extend
-- @param iterable Any object iterable by `ipairs`, including Lua tables, `Array`s and `Pool*Array`s.
methods.extend = function(self, iterable)
if ffi_istype(PoolVector3Array, iterable) then
api.godot_pool_vector3_array_append_array(self, iterable)
else
for _, b in ipairs(iterable) do
self:push_back(b)
end
end
end
--- Returns a String with each element of the array joined with the given `delimiter`.
-- @function join
-- @param[opt=""] delimiter
-- @treturn String
methods.join = array_join
--- Returns array's buffer as a PoolByteArray.
-- @function get_buffer
-- @treturn PoolByteArray
methods.get_buffer = array_generate_get_buffer(Vector3)
--- Static Functions.
-- These don't receive `self` and should be called directly as `PoolVector3Array.static_function(...)`
-- @section static_funcs
--- Create a new array with the elements from `iterable`.
-- @usage
-- local array = PoolVector3Array.from(some_table_or_other_iterable)
-- @function from
-- @param iterable If another PoolVector3Array is passed, return a copy of it.
-- Otherwise, the new array is `extend`ed with `iterable`.
-- @treturn PoolVector3Array
-- @see extend
methods.from = function(value)
local self = PoolVector3Array()
if ffi_istype(PoolVector3Array, value) then
api.godot_pool_vector3_array_new_copy(self, value)
elseif ffi_istype(Array, value) then
api.godot_pool_vector3_array_new_with_array(self, value)
else
methods.extend(self, value)
end
return self
end
--- Metamethods
-- @section metamethods
PoolVector3Array = ffi_metatype('godot_pool_vector3_array', {
--- PoolVector3Array constructor, called by the idiom `PoolVector3Array(...)`.
-- @function __new
-- @param ... Initial elements, added with `push_back`
-- @treturn PoolVector3Array
__new = function(mt, ...)
local self = ffi_new(mt)
api.godot_pool_vector3_array_new(self)
methods.push_back(self, ...)
return self
end,
__gc = api.godot_pool_vector3_array_destroy,
--- Returns method named `index` or the result of `safe_get(index - 1)`.
--
-- Like Lua tables, indices start at 1. For 0-based indexing, call `get` or
-- `safe_get` directly.
-- @function __index
-- @param index
-- @return Method or element or `nil`
-- @see safe_get
__index = array_generate__index(methods),
--- Alias for `safe_set(index - 1, value)`.
--
-- Like Lua tables, indices start at 1. For 0-based indexing, call `set` or
-- `safe_set` directly.
-- @function __newindex
-- @tparam int index
-- @param value
-- @see safe_set
__newindex = array__newindex,
--- Returns a Lua string representation of this array.
-- @function __tostring
-- @treturn string
__tostring = gd_tostring,
--- Concatenates values.
-- @function __concat
-- @param a First value, stringified with `GD.str`
-- @param b First value, stringified with `GD.str`
-- @treturn String
__concat = concat_gdvalues,
--- Alias for `size`.
-- @function __len
-- @treturn int
-- @see size
__len = array__len,
--- Returns an iterator for array's elements, called by the idiom `ipairs(array)`.
-- @usage
-- for i, vector in ipairs(array) do
-- -- do something
-- end
-- @function __ipairs
-- @treturn function
-- @treturn PoolVector3Array self
-- @treturn int 0
__ipairs = array_ipairs,
--- Alias for `__ipairs`, called by the idiom `pairs(array)`.
-- @function __pairs
-- @treturn function
-- @treturn PoolVector3Array self
-- @treturn int 0
-- @see __ipairs
__pairs = array_ipairs,
})