-
array:tojson ()
-
render an array as valid json
Returns:
json string
See also:
Usage:
print(a:tojson())
-
array:insert (pos, elm)
-
Inserts an element at position.
Parameters:
- pos
a valid index to insert item.
- elm
any
Returns:
updated length of array.
Usage:
local a = JSON:array(1,2,3.45,"test",true,null)
print(a:tojson()) a:insert(0,0)
print(a:tojson())
-
array:del (pos)
-
Deletes an element at position.
Parameters:
- pos
index of item to be removed.
Returns:
the updated length of array.
Usage:
local a = JSON:array(0,1,2,3.45,"test",true,null)
print(a:tojson()) print(a:len()) print(#a) local n = a:del(4)
print(a:tojson()) print(n) print(#a) print(a:len())
-
array:reverse ()
-
reverses the indexes of the elements of an array.
Returns:
1 on success, 0 on failure.
Usage:
local a = JSON:array(0,1,2,3.45,"test",true,null)
print(a:tojson()) a:reverse()
print(a:tojson())
-
array:push (elm)
-
Adds element to the end of an array.
Parameters:
Returns:
the updated length of array.
Usage:
local a = JSON:array(0,1,2,3.45,true,null)
print(a:tojson()) print(a:len()) print(#a) local n = a:push("test")
print(a:tojson()) print(n) print(#a) print(a:len())
-
array:pop ()
-
Pops and returns the last element of an array.
Returns:
the popped element or nil if array is empty.
Usage:
local a = JSON:array(0,1,2,3.45,true,null)
print(a:tojson()) print(a:len()) print(#a) local n = a:pop()
print(a:tojson()) print(n) print(#a) print(a:len())
-
array:shift ()
-
Removes element at index 0.
Returns:
the removed element or nil if array is empty.
Usage:
local a = JSON:array(0,1,2,3.45,true,null)
print(a:tojson()) print(a:len()) print(#a) local n = a:shift()
print(a:tojson()) print(n) print(#a) print(a:len())
-
array:unshift (elm[, ...])
-
adds one or more elements to the beginning of an array.
Parameters:
- elm
Any
- ...
Any
(optional)
Returns:
the updated length of the array.
Usage:
local a = JSON:array(0,1,2,3.45,true,null)
print(a:tojson()) print(a:len()) print(#a) local n = a:unshift(9,8,7)
print(a:tojson()) print(n) print(#a) print(a:len())
-
array:ref ()
-
Creates a new reference to an existing array. (pass by reference)
Returns:
reference to array.
See also:
Usage:
local a_ref = a:ref()
print(a_ref[0]) print(a_ref[#a_ref - 1]) a_ref[0] = 20
print(a_ref[0], a[0])
-
array:unref ()
-
Creates an unreferenced copy of an existing array. (pass by value)
Returns:
unreference an array. (create a seperate copy)
See also:
Usage:
local a_copy = a:unref()
print(a_copy[0]) a_copy[0] = 20
print(a_copy[0], a[0])