Module src/gnome/closure.c

Functions

local _check_automatic (L, cl, arg_nr, func_name) Disallow the usage of automatic closures, which are created on-the-fly and destroyed after the called function returns, in certain situations.
local _closure_push_arguments (L, cl, ar, args) Push all arguments for the Lua closure on the stack by using the ffi2lua conversion functions.
local _closure_return_values (L, cl, ar, index, args, retval) Convert all return values to FFI, i.e. return them to the C caller.
local _convert_retval (value, ar) Call the appropriate function to convert the return value(s) of the Lua function to a FFI value.
local _setup_closure (L, cl, ts, arg_nr, func_name) The first time a closure is used, it is configured for the arguments that can be expected from the caller, i.e. the function signature.
local closure_handler (cif, retval, args, userdata) Call the Lua function from C, passing the required parameters.
local l_closure (L) Create a new userdata representing a closure.
local l_closure_call (L) Normally, a closure should be called by a C library.
local l_closure_gc (L) Garbage collection of a closure.
local l_closure_tostring (L) Pretty printing of a closure
lg_create_closure (L, index, is_automatic) Create a new closure for the function at the given index, and push that onto the Lua stack.
lg_done_closure () If the user has set the RUNTIME_DEBUG_CLOSURES flag, closures are not freed but kept in a singly linked list to detect accesses to already freed closures.
lg_use_closure (L, index, ts, arg_nr, func_name) A closure should now be used as a function argument, or stored in a structure's virtual table.
local set_ffi_types (L, ts, arg_types) Initialize the arg_types array with the types taken from the function's signature.


Functions

local _check_automatic (L, cl, arg_nr, func_name)
Disallow the usage of automatic closures, which are created on-the-fly and destroyed after the called function returns, in certain situations.

Parameters

  • L:
  • cl:
  • arg_nr:
  • func_name:
In file: src/gnome/closure.c line 473
local _closure_push_arguments (L, cl, ar, args)
Push all arguments for the Lua closure on the stack by using the ffi2lua conversion functions.

Parameters

  • L:
  • cl:
  • ar:
  • args:
In file: src/gnome/closure.c line 66
local _closure_return_values (L, cl, ar, index, args, retval)
Convert all return values to FFI, i.e. return them to the C caller. Multiple return values may be given - for the output arguments. The first result is stored in *retval (if not void), the others are used one by one for the output arguments in order. Lua Stack: [index] = first return value

Parameters

  • L: Lua State
  • cl: Information about the callback function that was just called
  • ar: argconv_t structure, partly initialized (esp. with ar->ci)
  • index: Stack position of the first return value from the callback
  • args: Array of the arguments passed by the caller
  • retval: Location where to store the callback's return value
In file: src/gnome/closure.c line 103
local _convert_retval (value, ar)
Call the appropriate function to convert the return value(s) of the Lua function to a FFI value. This is a simple wrapper to allow using pcall() to catch conversion errors.

Parameters

  • value: A Lua value of arbitrary type.
  • ar: A struct argconv_t
In file: src/gnome/closure.c line 48
local _setup_closure (L, cl, ts, arg_nr, func_name)
The first time a closure is used, it is configured for the arguments that can be expected from the caller, i.e. the function signature.

Parameters

  • L:
  • cl:
  • ts:
  • arg_nr:
  • func_name:
In file: src/gnome/closure.c line 504
local closure_handler (cif, retval, args, userdata)
Call the Lua function from C, passing the required parameters. Cave: when a struct lua_closure is freed, and a new one is allocated in exactly the same location (not improbable), then the arguments in "args" won't match the Lua function's signature - leading to SEGV or similar. How can this be detected??

Parameters

  • cif: The "cif", specification of the arguments
  • retval: Location where to store the return value
  • args: Array of arguments
  • userdata: Pointer to the "struct lua_closure"
In file: src/gnome/closure.c line 195
local l_closure (L)
Create a new userdata representing a closure. The function signature will be known later, when this closure is used somewhere, e.g. as argument to a Gtk function.

Parameters

  • L:
In file: src/gnome/closure.c line 581
local l_closure_call (L)
Normally, a closure should be called by a C library. It is possible, though, to call it from Lua too. Simply replace the closure object with the function, then call with all arguments given and return all return values.

Parameters

  • L:
In file: src/gnome/closure.c line 338
local l_closure_gc (L)
Garbage collection of a closure. Note that the user must ensure it won't be called again! Otherwise, random SEGV are likely to occur.

Parameters

  • L:
In file: src/gnome/closure.c line 308
local l_closure_tostring (L)
Pretty printing of a closure

Parameters

  • L:
In file: src/gnome/closure.c line 354
lg_create_closure (L, index, is_automatic)
Create a new closure for the function at the given index, and push that onto the Lua stack. Note that such closures don't include any extra arguments, just the function.

Parameters

  • L: Lua State
  • index: Position on the Lua stack where the function object is
  • is_automatic: The corresponding field in the new closure is set to this value.
In file: src/gnome/closure.c line 592
lg_done_closure ()
If the user has set the RUNTIME_DEBUG_CLOSURES flag, closures are not freed but kept in a singly linked list to detect accesses to already freed closures. At program termination, or when this debug flag is unset, free them. In file: src/gnome/closure.c line 637
lg_use_closure (L, index, ts, arg_nr, func_name)
A closure should now be used as a function argument, or stored in a structure's virtual table. Now that the signature of the function is known, setup the ffi closure.

Parameters

  • L: Lua state
  • index: Stack position of a closure
  • ts: The typespec (and therefore, signature) of the function to call
  • arg_nr: If this is an argument to a function, which argument
  • func_name: Name of the called function, or structure element name

Return value:

Pointer to a new closure In file: src/gnome/closure.c line 538
local set_ffi_types (L, ts, arg_types)
Initialize the arg_types array with the types taken from the function's signature. If called with arg_types == NULL, just count the number of args. The first byte is the length of the following data.

Parameters

  • L:
  • ts: Type of the function to call
  • arg_types: Location to store the ffi argument types (may be NULL)

Return value:

The number of arguments. In file: src/gnome/closure.c line 261

Valid XHTML 1.0!