Wireshark 4.5.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions | Variables
wslua.h File Reference
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <ws_log_defs.h>
#include <wiretap/wtap.h>
#include <wsutil/report_message.h>
#include <wsutil/nstime.h>
#include <wsutil/ws_assert.h>
#include <wsutil/wslog.h>
#include <epan/packet.h>
#include <epan/strutil.h>
#include <epan/to_str.h>
#include <epan/prefs.h>
#include <epan/proto.h>
#include <epan/epan_dissect.h>
#include <epan/tap.h>
#include <epan/column-utils.h>
#include <wsutil/filesystem.h>
#include <epan/funnel.h>
#include <epan/tvbparse.h>
#include <epan/epan.h>
#include <epan/expert.h>
#include <epan/exceptions.h>
#include <epan/show_exception.h>
#include <epan/wslua/declare_wslua.h>

Go to the source code of this file.

Classes

struct  _wslua_tvb
 
struct  _wslua_pinfo
 
struct  _wslua_tvbrange
 
struct  _wslua_tw
 
struct  _wslua_field_t
 
struct  _wslua_expert_field_t
 
struct  _wslua_pref_t
 
struct  _wslua_proto_t
 
struct  _wslua_distbl_t
 
struct  _wslua_col_info
 
struct  _wslua_cols
 
struct  _wslua_private_table
 
struct  _wslua_treeitem
 
struct  _wslua_header_field_info
 
struct  _wslua_field_info
 
struct  _wslua_tap
 
struct  _wslua_file
 
struct  _wslua_captureinfo
 
struct  _wslua_phdr
 
struct  _wslua_const_phdr
 
struct  _wslua_filehandler
 
struct  _wslua_dir
 
struct  _wslua_progdlg
 
struct  tappable_t
 
struct  wslua_ft_types_t
 
struct  _wslua_attribute_table
 
struct  _wslua_class
 Type for defining new classes. More...
 

Macros

#define WSLUA_INIT_ROUTINES   "init_routines"
 
#define WSLUA_PREFS_CHANGED   "prefs_changed"
 
#define wslua_toint(L, i)   (int) ( lua_tointeger(L,i) )
 
#define wslua_toint32(L, i)   (int32_t) ( lua_tointeger(L,i) )
 
#define wslua_toint64(L, i)   (int64_t) ( lua_tonumber(L,i) )
 
#define wslua_touint64(L, i)   (uint64_t) ( lua_tonumber(L,i) )
 
#define wslua_checkint(L, i)   (int) ( luaL_checkinteger(L,i) )
 
#define wslua_checkint32(L, i)   (int32_t) ( luaL_checkinteger(L,i) )
 
#define wslua_checkint64(L, i)   (int64_t) ( luaL_checknumber(L,i) )
 
#define wslua_checkuint64(L, i)   (uint64_t) ( luaL_checknumber(L,i) )
 
#define wslua_optint(L, i, d)   (int) ( luaL_optinteger(L,i,d) )
 
#define wslua_optint32(L, i, d)   (int32_t) ( luaL_optinteger(L,i,d) )
 
#define wslua_optint64(L, i, d)   (int64_t) ( luaL_optnumber(L,i,d) )
 
#define wslua_optuint64(L, i, d)   (uint64_t) ( luaL_optnumber(L,i,d) )
 
#define wslua_touint(L, i)   (unsigned) ( lua_tounsigned(L,i) )
 
#define wslua_touint32(L, i)   (uint32_t) ( lua_tounsigned(L,i) )
 
#define wslua_checkuint(L, i)   (unsigned) ( luaL_checkunsigned(L,i) )
 
#define wslua_checkuint32(L, i)   (uint32_t) ( luaL_checkunsigned(L,i) )
 
#define wslua_optuint(L, i, d)   (unsigned) ( luaL_optunsigned(L,i,d) )
 
#define wslua_optuint32(L, i, d)   (uint32_t) ( luaL_optunsigned(L,i,d) )
 
#define WSLUA_CLASS_DEFINE(C, check_code)    WSLUA_CLASS_DEFINE_BASE(C,check_code,NULL)
 
#define WSLUA_CLASS_DEFINE_BASE(C, check_code, retval)
 
#define WSLUA_TYPEOF_FIELD   "__typeof"
 
#define WSLUA_FUNCTION   extern int
 
#define WSLUA_INTERNAL_FUNCTION   extern int
 
#define WSLUA_REGISTER_FUNCTION(name)   { lua_pushcfunction(L, wslua_## name); lua_setglobal(L, #name); }
 
#define WSLUA_REGISTER   extern int
 
#define WSLUA_METHOD   static int
 
#define WSLUA_CONSTRUCTOR   static int
 
#define WSLUA_ATTR_SET   static int
 
#define WSLUA_ATTR_GET   static int
 
#define WSLUA_METAMETHOD   static int
 
#define WSLUA_METHODS   static const luaL_Reg
 
#define WSLUA_META   static const luaL_Reg
 
#define WSLUA_CLASS_FNREG(class, name)   { #name, class##_##name }
 
#define WSLUA_CLASS_FNREG_ALIAS(class, aliasname, name)   { #aliasname, class##_##name }
 
#define WSLUA_CLASS_MTREG(class, name)   { "__" #name, class##__##name }
 
#define WSLUA_ATTRIBUTES   static const wslua_attribute_table
 
#define WSLUA_ATTRIBUTE_RWREG(class, name)   { #name, class##_get_##name, class##_set_##name }
 
#define WSLUA_ATTRIBUTE_ROREG(class, name)   { #name, class##_get_##name, NULL }
 
#define WSLUA_ATTRIBUTE_WOREG(class, name)   { #name, NULL, class##_set_##name }
 
#define WSLUA_ATTRIBUTE_FUNC_SETTER(C, field)
 
#define WSLUA_ATTRIBUTE_GET(C, name, block)
 
#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_GETTER(C, name, member)    WSLUA_ATTRIBUTE_GET(C,name,{lua_pushboolean(L, obj->member );})
 
#define WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C, name, member)    WSLUA_ATTRIBUTE_GET(C,name,{lua_pushinteger(L,(lua_Integer)(obj->member));})
 
#define WSLUA_ATTRIBUTE_INTEGER_GETTER(C, member)    WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,member,member)
 
#define WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(C, name, block)    WSLUA_ATTRIBUTE_GET(C,name,{lua_pushnumber(L,(lua_Number)(block));})
 
#define WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C, name, member)
 
#define WSLUA_ATTRIBUTE_STRING_GETTER(C, member)    WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,member,member)
 
#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(C, name, member, option)
 
#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER(C, name, member, option)
 
#define WSLUA_ATTRIBUTE_SET(C, name, block)
 
#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER(C, name, member)
 
#define WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C, name, member, cast)
 
#define WSLUA_ATTRIBUTE_INTEGER_SETTER(C, member, cast)    WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,member,member,cast)
 
#define WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C, field, member, need_free)
 
#define WSLUA_ATTRIBUTE_STRING_SETTER(C, field, need_free)    WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,field,need_free)
 
#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(C, field, member, option)
 
#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER(C, field, member, option)
 
#define WSLUA_ERROR(name, error)   { luaL_error(L, "%s%s", #name ": ", error); }
 
#define WSLUA_ARG_ERROR(name, attr, error)   { luaL_argerror(L,WSLUA_ARG_ ## name ## _ ## attr, #name ": " error); }
 
#define WSLUA_OPTARG_ERROR(name, attr, error)   { luaL_argerror(L,WSLUA_OPTARG_##name##_ ##attr, #name ": " error); }
 
#define WSLUA_REG_GLOBAL_BOOL(L, n, v)   { lua_pushboolean(L,v); lua_setglobal(L,n); }
 
#define WSLUA_REG_GLOBAL_STRING(L, n, v)   { lua_pushstring(L,v); lua_setglobal(L,n); }
 
#define WSLUA_REG_GLOBAL_INTEGER(L, n, v)   { lua_pushinteger(L,v); lua_setglobal(L,n); }
 
#define WSLUA_RETURN(i)   return (i)
 
#define WSLUA_API   extern
 
#define NOP   (void)p
 
#define FAIL_ON_NULL(s)   if (! *p) luaL_argerror(L,idx,"null " s)
 
#define FAIL_ON_NULL_OR_EXPIRED(s)
 
#define CLEAR_OUTSTANDING(C, marker, marker_val)
 
#define WSLUA_CLASS_DECLARE(C)
 
#define THROW_LUA_ERROR(...)    THROW_FORMATTED(DissectorError, __VA_ARGS__)
 
#define WRAP_NON_LUA_EXCEPTIONS(code)
 

Typedefs

typedef struct _wslua_field_t wslua_field_t
 
typedef struct _wslua_expert_field_t wslua_expert_field_t
 
typedef struct _wslua_pref_t wslua_pref_t
 
typedef struct _wslua_proto_t wslua_proto_t
 
typedef void(* tap_extractor_t) (lua_State *, const void *)
 
typedef wslua_pref_tPref
 
typedef wslua_pref_tPrefs
 
typedef struct _wslua_field_tProtoField
 
typedef struct _wslua_expert_field_tProtoExpert
 
typedef struct _wslua_proto_tProto
 
typedef struct _wslua_distbl_tDissectorTable
 
typedef dissector_handle_t Dissector
 
typedef GByteArray * ByteArray
 
typedef struct _wslua_tvbTvb
 
typedef struct _wslua_tvbrangeTvbRange
 
typedef struct _wslua_col_infoColumn
 
typedef struct _wslua_colsColumns
 
typedef struct _wslua_pinfoPinfo
 
typedef struct _wslua_treeitemTreeItem
 
typedef addressAddress
 
typedef nstime_tNSTime
 
typedef int64_t Int64
 
typedef uint64_t UInt64
 
typedef struct _wslua_header_field_infoField
 
typedef struct _wslua_field_infoFieldInfo
 
typedef struct _wslua_tapListener
 
typedef struct _wslua_twTextWindow
 
typedef struct _wslua_progdlgProgDlg
 
typedef struct _wslua_fileFile
 
typedef struct _wslua_captureinfoCaptureInfo
 
typedef struct _wslua_captureinfoCaptureInfoConst
 
typedef struct _wslua_phdrFrameInfo
 
typedef struct _wslua_const_phdrFrameInfoConst
 
typedef struct _wslua_filehandlerFileHandler
 
typedef wtap_dumperDumper
 
typedef struct lua_pseudo_headerPseudoHeader
 
typedef tvbparse_tParser
 
typedef tvbparse_wanted_tRule
 
typedef tvbparse_elem_tNode
 
typedef tvbparse_action_t * Shortcut
 
typedef struct _wslua_dirDir
 
typedef struct _wslua_private_tablePrivateTable
 
typedef char * Struct
 
typedef struct _wslua_attribute_table wslua_attribute_table
 
typedef struct _wslua_class wslua_class
 Type for defining new classes.
 

Enumerations

enum  pref_type_t {
  PREF_UINT , PREF_BOOL , PREF_ENUM , PREF_STRING ,
  PREF_RANGE , PREF_STATIC_TEXT , PREF_OBSOLETE
}
 

Functions

int wslua_reg_attributes (lua_State *L, const wslua_attribute_table *t, bool is_getter)
 
lua_State * wslua_state (void)
 
void wslua_register_classinstance_meta (lua_State *L, const wslua_class *cls_def)
 
void wslua_register_class (lua_State *L, const wslua_class *cls_def)
 
int wslua__concat (lua_State *L)
 
bool wslua_toboolean (lua_State *L, int n)
 
bool wslua_checkboolean (lua_State *L, int n)
 
bool wslua_optbool (lua_State *L, int n, bool def)
 
lua_Integer wslua_tointeger (lua_State *L, int n)
 
int wslua_optboolint (lua_State *L, int n, int def)
 
const char * wslua_checklstring_only (lua_State *L, int n, size_t *l)
 
const char * wslua_checkstring_only (lua_State *L, int n)
 
void wslua_setfuncs (lua_State *L, const luaL_Reg *l, int nup)
 
const char * wslua_typeof (lua_State *L, int idx)
 
bool wslua_get_table (lua_State *L, int idx, const char *name)
 
bool wslua_get_field (lua_State *L, int idx, const char *name)
 
int dissect_lua (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
 
bool heur_dissect_lua (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
 
expert_fieldwslua_get_expert_field (const int group, const int severity)
 
void wslua_prefs_changed (void)
 
void proto_register_lua (void)
 
GString * lua_register_all_taps (void)
 
void wslua_prime_dfilter (epan_dissect_t *edt)
 
bool wslua_has_field_extractors (void)
 
void lua_prime_all_fields (proto_tree *tree)
 
int Proto_commit (lua_State *L)
 
TreeItem create_TreeItem (proto_tree *tree, proto_item *item)
 
void clear_outstanding_FuncSavers (void)
 
void Int64_pack (lua_State *L, luaL_Buffer *b, int idx, bool asLittleEndian)
 
int Int64_unpack (lua_State *L, const char *buff, bool asLittleEndian)
 
void UInt64_pack (lua_State *L, luaL_Buffer *b, int idx, bool asLittleEndian)
 
int UInt64_unpack (lua_State *L, const char *buff, bool asLittleEndian)
 
uint64_t getUInt64 (lua_State *L, int i)
 
Tvbpush_Tvb (lua_State *L, tvbuff_t *tvb)
 
int push_wsluaTvb (lua_State *L, Tvb t)
 
bool push_TvbRange (lua_State *L, tvbuff_t *tvb, int offset, int len)
 
void clear_outstanding_Tvb (void)
 
void clear_outstanding_TvbRange (void)
 
Pinfopush_Pinfo (lua_State *L, packet_info *p)
 
void clear_outstanding_Pinfo (void)
 
void clear_outstanding_Column (void)
 
void clear_outstanding_Columns (void)
 
void clear_outstanding_PrivateTable (void)
 
int get_hf_wslua_text (void)
 
TreeItem push_TreeItem (lua_State *L, proto_tree *tree, proto_item *item)
 
void clear_outstanding_TreeItem (void)
 
FieldInfopush_FieldInfo (lua_State *L, field_info *f)
 
void clear_outstanding_FieldInfo (void)
 
void wslua_print_stack (char *s, lua_State *L)
 
void wslua_init (register_cb cb, void *client_data)
 
void wslua_early_cleanup (void)
 
void wslua_cleanup (void)
 
tap_extractor_t wslua_get_tap_extractor (const char *name)
 
int wslua_set_tap_enums (lua_State *L)
 
ProtoField wslua_is_field_available (lua_State *L, const char *field_abbr)
 
char * wslua_get_actual_filename (const char *fname)
 
int wslua_bin2hex (lua_State *L, const uint8_t *data, const unsigned len, const bool lowercase, const char *sep)
 
int wslua_hex2bin (lua_State *L, const char *data, const unsigned len, const char *sep)
 
int luaopen_rex_pcre2 (lua_State *L)
 
const char * get_current_plugin_version (void)
 
void clear_current_plugin_version (void)
 
int wslua_deregister_heur_dissectors (lua_State *L)
 
int wslua_deregister_protocols (lua_State *L)
 
int wslua_deregister_dissector_tables (lua_State *L)
 
int wslua_deregister_listeners (lua_State *L)
 
int wslua_deregister_fields (lua_State *L)
 
int wslua_deregister_filehandlers (lua_State *L)
 
void wslua_deregister_menus (void)
 
void wslua_init_wtap_filetypes (lua_State *L)
 

Variables

packet_infolua_pinfo
 
TreeItem lua_tree
 
tvbuff_tlua_tvb
 
bool lua_initialized
 
int lua_dissectors_table_ref
 
int lua_heur_dissectors_table_ref
 
const char * wslua_typeof_unknown
 

Macro Definition Documentation

◆ CLEAR_OUTSTANDING

#define CLEAR_OUTSTANDING (   C,
  marker,
  marker_val 
)
Value:
void clear_outstanding_##C(void) { \
while (outstanding_##C->len) { \
C p = (C)g_ptr_array_remove_index_fast(outstanding_##C,0); \
if (p) { \
if (p->marker != marker_val) \
p->marker = marker_val; \
else \
g_free(p); \
} \
} \
}

◆ FAIL_ON_NULL_OR_EXPIRED

#define FAIL_ON_NULL_OR_EXPIRED (   s)
Value:
if (!*p) { \
luaL_argerror(L,idx,"null " s); \
} else if ((*p)->expired) { \
luaL_argerror(L,idx,"expired " s); \
}

◆ WRAP_NON_LUA_EXCEPTIONS

#define WRAP_NON_LUA_EXCEPTIONS (   code)
Value:
{ \
volatile bool has_error = false; \
TRY { \
code \
show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
} CATCH_ALL { \
show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
lua_pushfstring(L, "%s: %s", __func__, GET_MESSAGE ? GET_MESSAGE : "Malformed packet"); \
has_error = true; \
} ENDTRY; \
if (has_error) { lua_error(L); } \
}
#define BoundsError
Definition exceptions.h:28
#define ScsiBoundsError
Definition exceptions.h:87
#define FragmentBoundsError
Definition exceptions.h:60

◆ WSLUA_ATTRIBUTE_FUNC_SETTER

#define WSLUA_ATTRIBUTE_FUNC_SETTER (   C,
  field 
)
Value:
static int C##_set_##field (lua_State* L) { \
C obj = check##C (L,1); \
if (! lua_isfunction(L,-1) ) \
return luaL_error(L, "%s's attribute `%s' must be a function", #C , #field ); \
if (obj->field##_ref != LUA_NOREF) \
/* there was one registered before, remove it */ \
luaL_unref(L, LUA_REGISTRYINDEX, obj->field##_ref); \
obj->field##_ref = luaL_ref(L, LUA_REGISTRYINDEX); \
return 0; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_set_##field

◆ WSLUA_ATTRIBUTE_GET

#define WSLUA_ATTRIBUTE_GET (   C,
  name,
  block 
)
Value:
static int C##_get_##name (lua_State* L) { \
C obj = check##C (L,1); \
block \
return 1; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_get_##name

◆ WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER

#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER (   C,
  name,
  member 
)
Value:
WSLUA_ATTRIBUTE_SET(C,name, { \
if (! lua_isboolean(L,-1) ) \
return luaL_error(L, "%s's attribute `%s' must be a boolean", #C , #name ); \
obj->member = lua_toboolean(L,-1); \
})

◆ WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER

#define WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER (   C,
  name,
  member,
  cast 
)
Value:
WSLUA_ATTRIBUTE_SET(C,name, { \
if (! lua_isinteger(L,-1) ) \
return luaL_error(L, "%s's attribute `%s' must be an integer", #C , #name ); \
obj->member = (cast) wslua_toint32(L,-1); \
})

◆ WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER

#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER (   C,
  name,
  member,
  option 
)
Value:
WSLUA_ATTRIBUTE_GET(C,name, { \
char* str; \
if ((obj->member) && (obj->member->len > 0)) { \
if (wtap_block_get_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, &str) == WTAP_OPTTYPE_SUCCESS) { \
lua_pushstring(L,str); \
} \
} \
})
Definition wtap_opttypes.c:85

◆ WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER

#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER (   C,
  field,
  member,
  option 
)
Value:
static int C##_set_##field (lua_State* L) { \
C obj = check##C (L,1); \
char* s = NULL; \
if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
s = g_strdup(lua_tostring(L,-1)); \
} else { \
return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
} \
if ((obj->member) && (obj->member->len > 0)) { \
wtap_block_set_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, s, strlen(s)); \
} \
g_free(s); \
return 0; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_set_##field

◆ WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER

#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER (   C,
  name,
  member,
  option 
)
Value:
WSLUA_ATTRIBUTE_GET(C,name, { \
char* str; \
if ((obj->member) && (obj->member->len > 0)) { \
if (wtap_block_get_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, &str) == WTAP_OPTTYPE_SUCCESS) { \
lua_pushstring(L,str); \
} \
} \
})

◆ WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER

#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER (   C,
  field,
  member,
  option 
)
Value:
static int C##_set_##field (lua_State* L) { \
C obj = check##C (L,1); \
char* s = NULL; \
if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
s = g_strdup(lua_tostring(L,-1)); \
} else { \
return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
} \
if ((obj->member) && (obj->member->len > 0)) { \
wtap_block_set_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, s, strlen(s)); \
} \
g_free(s); \
return 0; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_set_##field

◆ WSLUA_ATTRIBUTE_NAMED_STRING_GETTER

#define WSLUA_ATTRIBUTE_NAMED_STRING_GETTER (   C,
  name,
  member 
)
Value:
WSLUA_ATTRIBUTE_GET(C,name, { \
lua_pushstring(L,obj->member); /* this pushes nil if obj->member is null */ \
})

◆ WSLUA_ATTRIBUTE_NAMED_STRING_SETTER

#define WSLUA_ATTRIBUTE_NAMED_STRING_SETTER (   C,
  field,
  member,
  need_free 
)
Value:
static int C##_set_##field (lua_State* L) { \
C obj = check##C (L,1); \
char* s = NULL; \
if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
s = g_strdup(lua_tostring(L,-1)); \
} else { \
return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
} \
if (obj->member != NULL && need_free) \
g_free((void*) obj->member); \
obj->member = s; \
return 0; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_set_##field

◆ WSLUA_ATTRIBUTE_SET

#define WSLUA_ATTRIBUTE_SET (   C,
  name,
  block 
)
Value:
static int C##_set_##name (lua_State* L) { \
C obj = check##C (L,1); \
block; \
return 0; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_set_##name

◆ WSLUA_CLASS_DECLARE

#define WSLUA_CLASS_DECLARE (   C)
Value:
extern C to##C(lua_State* L, int idx); \
extern C check##C(lua_State* L, int idx); \
extern C* push##C(lua_State* L, C v); \
extern int C##_register(lua_State* L); \
extern bool is##C(lua_State* L,int i); \
extern C shift##C(lua_State* L,int i)

◆ wslua_touint

#define wslua_touint (   L,
 
)    (unsigned) ( lua_tounsigned(L,i) )

On Lua 5.3 and later, the unsigned conversions may not be defined (depending on a compatibility define), and they're just casts if they are.

Typedef Documentation

◆ wslua_class

typedef struct _wslua_class wslua_class

Type for defining new classes.

A new class is defined as a Lua table type. Instances of this class are created through pushXxx which sets the appropriate metatable.

Enumeration Type Documentation

◆ pref_type_t

PREF_OBSOLETE is used for preferences that a module used to support but no longer supports; we give different error messages for them.

Function Documentation

◆ wslua_is_field_available()

ProtoField wslua_is_field_available ( lua_State *  L,
const char *  field_abbr 
)
extern

Query field abbr that is defined and bound to a Proto in lua. They are not registered until the end of the initialization.

◆ wslua_register_class()

void wslua_register_class ( lua_State *  L,
const wslua_class cls_def 
)

Registers a new class for use in Lua with the specified properties. The metatable for the class instance is internally registered with the given name.

This functions basically creates a class (type table) with this structure:

Class = { class_methods } Class.__typeof = "Class" – NOTE: Might be removed in future Class.__metatable = { class_meta } Class.__metatable.__typeof = "Class" – NOTE: Might be removed in future Class.__metatable.__index = function_that_errors_out Class.__metatable.__newindex = function_that_errors_out

It also registers another metatable for class instances (type userdata):

mt = { instance_meta } mt.__typeof = "Class" – will be passed upvalues (see wslua_instancemeta_index_impl). mt.__index = function_that_finds_right_property_or_method_getter mt.__newindex = function_thaon_that_finds_right_property_or_method_setter

For backwards compatibility, introspection is still possible (this detail might be removed in the future though, do not rely on this!):

Class.__metatable.__methods = Class Class.__metatable.__getters = { __typeof = "getter", getter_attrs } Class.__metatable.__setters = { __typeof = "setter", setter_attrs }

◆ wslua_register_classinstance_meta()

void wslua_register_classinstance_meta ( lua_State *  L,
const wslua_class cls_def 
)

Registers the metatable for class instances. See the documentation of wslua_register_class for the exact metatable.