space_object extensions
You can extend space_object
with custom functions as follows:
- Create a Lua function.
- Add the function name to a predefined global variable
box.schema.space_mt
, which has thetable
type. Adding tobox.schema.space_mt
makes the function available for all spaces. - Call the function on the
space_object
:space_object:function-name([parameters])
.
Alternatively, you can make a user-defined function available for only one space
by calling getmetatable(space_object)
and then adding the function name to the
meta table.
See also: index_object extensions.
Example:
-- Visible to any space, no parameters.
-- After these requests, the value of global_variable will be 6.
box.schema.space.create('t')
box.space.t:create_index('i')
global_variable = 5
function f(space_arg) global_variable = global_variable + 1 end
box.schema.space_mt.counter = f
box.space.t:counter()