Next: , Previous: slua_tbl_next, Up: Manipulating Tables


A.2.3 slua_tbl_el

get an element from a table

Synopsis

     #include <luasup/luasup.h>
     
     
     
SLuaError slua_tbl_el( SLua_ErrFunc errfunc, lua_Object table, const char *err_pfx, const char *index, SLuaArgType type, void *dest );

Parameters

SLua_ErrFunc errfunc
the error function
lua_Object table
the table
const char *err_pfx
a prefix for error messages
const char *index
the index of the element to delete
SLuaArgType type
the type of argument to expect (with or'd flags )
          
          
Possible values for a SLuaArgType are as follows: SLua_STRING, SLua_NUMBER, SLua_TABLE, SLua_NIL, SLua_FUNCTION, SLua_CFUNCTION, SLua_USERDATA, SLua_TYPES, SLua_OPTIONAL, SLua_DELENTRY, SLua_COPY, SLua_BOGUS
void *dest
where to store the retrieved data

Description

This function retrieves the value of an element with index index in a table. The caller must specify the type of argument to expect. If the type is or'd with SLua_OPTIONAL the element need not be present. If the type is SLua_STRING and is or'd with SLua_COPY, a copy of the string value is returned (the caller must handle deallocation).

The value of the element is stored in the passed dest variable.

Upon error, the passed function errfunc is called with an error message. The message will be prefixed with the string in err_pfx (using "%s: error message"). errfunc may be NULL, in which case it won't be called.

Returns

It returns one of the following values:

0
everything went ok or the passed table was equal to LUA_NOOBJECT.
SLua_ENOEL
The element was optional, but not present.
SLua_ENOENT
The element was not in the table.
SLua_ENOMEM
The type was SLua_STRING|SLua_COPY and the string could not be duplicated.
SLua_ENOTYPE
The type is unknown.
SLua_ENOMATCH
The requested type and the actual type do not agree.

Possible values for a SLuaError are as follows: SLua_ENOERR, SLua_ENOENT, SLua_ENOMEM, SLua_ENOTYPE, SLua_ENOEL, SLua_ENOMATCH

Author

Diab Jerius