space_object:user_defined() | Tarantool
Submodule box.space space_object:user_defined()

space_object:user_defined()

object space_object
space_object:user_defined()

Users can define any functions they want, and associate them with spaces: in effect they can make their own space methods. They do this by:

  1. creating a Lua function,
  2. adding the function name to a predefined global variable which has type = table, and
  3. invoking the function any time thereafter, as long as the server is up, by saying space_object:function-name([parameters]).

The predefined global variable is box.schema.space_mt. Adding to box.schema.space_mt makes the method available for all spaces.

Alternatively, user-defined methods can be made available for only one space, by calling getmetatable(space_object) and then adding the function name to the meta table. See also the example for index_object:user_defined().

Parameters:
  • index_object (index_object) – an object reference.
  • any-name (any-type) – whatever the user defines

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()
Found what you were looking for?
Feedback