4 * Wireshark's interface to the Lua Programming Language
6 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
7 * (c) 2007, Tamas Regos <tamas.regos@ericsson.com>
8 * (c) 2008, Balint Reczey <balint.reczey@ericsson.com>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * SPDX-License-Identifier: GPL-2.0-or-later
29 #include <wiretap/wtap.h>
31 #include <wsutil/report_message.h>
32 #include <wsutil/nstime.h>
33 #include <wsutil/ws_assert.h>
34 #include <wsutil/wslog.h>
36 #include <epan/packet.h>
37 #include <epan/strutil.h>
38 #include <epan/to_str.h>
39 #include <epan/prefs.h>
40 #include <epan/proto.h>
41 #include <epan/epan_dissect.h>
43 #include <epan/column-utils.h>
44 #include <wsutil/filesystem.h>
45 #include <epan/funnel.h>
46 #include <epan/tvbparse.h>
47 #include <epan/epan.h>
48 #include <epan/expert.h>
50 #include <epan/wslua/declare_wslua.h>
53 * @ingroup wslua_group
56 #define WSLUA_INIT_ROUTINES "init_routines"
57 #define WSLUA_PREFS_CHANGED "prefs_changed"
59 typedef void (*wslua_logger_t)(const gchar *, GLogLevelFlags, const gchar *, gpointer);
60 extern wslua_logger_t wslua_logger;
62 /* type conversion macros - lua_Number is a double, so casting isn't kosher; and
63 using Lua's already-available lua_tointeger() and luaL_checkinteger() might be different
64 on different machines; so use these instead please! */
65 #define wslua_togint(L,i) (gint) ( lua_tointeger(L,i) )
66 #define wslua_togint32(L,i) (gint32) ( lua_tonumber(L,i) )
67 #define wslua_togint64(L,i) (gint64) ( lua_tonumber(L,i) )
68 #define wslua_toguint(L,i) (guint) ( lua_tointeger(L,i) )
69 #define wslua_toguint32(L,i) (guint32) ( lua_tonumber(L,i) )
70 #define wslua_toguint64(L,i) (guint64) ( lua_tonumber(L,i) )
72 #define wslua_checkgint(L,i) (gint) ( luaL_checkinteger(L,i) )
73 #define wslua_checkgint32(L,i) (gint32) ( luaL_checknumber(L,i) )
74 #define wslua_checkgint64(L,i) (gint64) ( luaL_checknumber(L,i) )
75 #define wslua_checkguint(L,i) (guint) ( luaL_checkinteger(L,i) )
76 #define wslua_checkguint32(L,i) (guint32) ( luaL_checknumber(L,i) )
77 #define wslua_checkguint64(L,i) (guint64) ( luaL_checknumber(L,i) )
79 #define wslua_optgint(L,i,d) (gint) ( luaL_optinteger(L,i,d) )
80 #define wslua_optgint32(L,i,d) (gint32) ( luaL_optnumber(L,i,d) )
81 #define wslua_optgint64(L,i,d) (gint64) ( luaL_optnumber(L,i,d) )
82 #define wslua_optguint(L,i,d) (guint) ( luaL_optinteger(L,i,d) )
83 #define wslua_optguint32(L,i,d) (guint32) ( luaL_optnumber(L,i,d) )
84 #define wslua_optguint64(L,i,d) (guint64) ( luaL_optnumber(L,i,d) )
94 packet_info* ws_pinfo;
98 struct _wslua_tvbrange {
99 struct _wslua_tvb* tvb;
105 funnel_text_window_t* ws_tw;
110 typedef struct _wslua_field_t {
122 typedef struct _wslua_expert_field_t {
128 } wslua_expert_field_t;
131 * PREF_OBSOLETE is used for preferences that a module used to support
132 * but no longer supports; we give different error messages for them.
144 typedef struct _wslua_pref_t {
158 guint32 max_value; /**< maximum value of a range */
160 const enum_val_t *enumvals; /**< list of name & values */
161 gboolean radio_buttons; /**< TRUE if it should be shown as
162 radio buttons rather than as an
163 option menu or combo box in
164 the preferences tab */
165 } enum_info; /**< for PREF_ENUM */
166 gchar* default_s; /**< default value for value.s */
167 } info; /**< display/text file information */
169 struct _wslua_pref_t* next;
170 struct _wslua_proto_t* proto;
171 int ref; /* Reference to enable Proto to deregister prefs. */
174 typedef struct _wslua_proto_t {
182 int expert_info_table_ref;
183 expert_module_t *expert_module;
184 module_t *prefs_module;
185 dissector_handle_t handle;
189 gboolean is_postdissector;
193 struct _wslua_distbl_t {
194 dissector_table_t table;
196 const gchar* ui_name;
201 struct _wslua_col_info {
212 struct _wslua_private_table {
214 gboolean is_allocated;
218 struct _wslua_treeitem {
224 // Internal structure for wslua_field.c to track info about registered fields.
225 struct _wslua_header_field_info {
227 header_field_info *hfi;
230 struct _wslua_field_info {
235 typedef void (*tap_extractor_t)(lua_State*,const void*);
240 tap_extractor_t extractor;
248 /* a "File" object can be different things under the hood. It can either
249 be a FILE_T from wtap struct, which it is during read operations, or it
250 can be a wtap_dumper struct during write operations. A wtap_dumper struct
251 has a FILE_T member, but we can't only store its pointer here because
252 dump operations need the whole thing to write out with. Ugh. */
255 wtap_dumper *wdh; /* will be NULL during read usage */
259 /* a "CaptureInfo" object can also be different things under the hood. */
260 struct _wslua_captureinfo {
261 wtap *wth; /* will be NULL during write usage */
262 wtap_dumper *wdh; /* will be NULL during read usage */
267 wtap_rec *rec; /* this also exists in wtap struct, but is different for seek_read ops */
268 Buffer *buf; /* can't use the one in wtap because it's different for seek_read ops */
272 struct _wslua_const_phdr {
278 struct _wslua_filehandler {
279 struct file_type_subtype_info finfo;
282 gchar* internal_description; /* XXX - this is redundant; finfo.description should suffice */
290 int seq_read_close_ref;
291 int can_write_encap_ref;
304 struct _wslua_progdlg {
311 typedef struct { const char* name; tap_extractor_t extractor; } tappable_t;
313 typedef struct {const gchar* str; enum ftenum id; } wslua_ft_types_t;
315 typedef wslua_pref_t* Pref;
316 typedef wslua_pref_t* Prefs;
317 typedef struct _wslua_field_t* ProtoField;
318 typedef struct _wslua_expert_field_t* ProtoExpert;
319 typedef struct _wslua_proto_t* Proto;
320 typedef struct _wslua_distbl_t* DissectorTable;
321 typedef dissector_handle_t Dissector;
322 typedef GByteArray* ByteArray;
323 typedef struct _wslua_tvb* Tvb;
324 typedef struct _wslua_tvbrange* TvbRange;
325 typedef struct _wslua_col_info* Column;
326 typedef struct _wslua_cols* Columns;
327 typedef struct _wslua_pinfo* Pinfo;
328 typedef struct _wslua_treeitem* TreeItem;
329 typedef address* Address;
330 typedef nstime_t* NSTime;
331 typedef gint64 Int64;
332 typedef guint64 UInt64;
333 typedef struct _wslua_header_field_info* Field;
334 typedef struct _wslua_field_info* FieldInfo;
335 typedef struct _wslua_tap* Listener;
336 typedef struct _wslua_tw* TextWindow;
337 typedef struct _wslua_progdlg* ProgDlg;
338 typedef struct _wslua_file* File;
339 typedef struct _wslua_captureinfo* CaptureInfo;
340 typedef struct _wslua_captureinfo* CaptureInfoConst;
341 typedef struct _wslua_phdr* FrameInfo;
342 typedef struct _wslua_const_phdr* FrameInfoConst;
343 typedef struct _wslua_filehandler* FileHandler;
344 typedef wtap_dumper* Dumper;
345 typedef struct lua_pseudo_header* PseudoHeader;
346 typedef tvbparse_t* Parser;
347 typedef tvbparse_wanted_t* Rule;
348 typedef tvbparse_elem_t* Node;
349 typedef tvbparse_action_t* Shortcut;
350 typedef struct _wslua_dir* Dir;
351 typedef struct _wslua_private_table* PrivateTable;
352 typedef gchar* Struct;
355 * toXxx(L,idx) gets a Xxx from an index (Lua Error if fails)
356 * checkXxx(L,idx) gets a Xxx from an index after calling check_code (No Lua Error if it fails)
357 * pushXxx(L,xxx) pushes an Xxx into the stack
358 * isXxx(L,idx) tests whether we have an Xxx at idx
359 * shiftXxx(L,idx) removes and returns an Xxx from idx only if it has a type of Xxx, returns NULL otherwise
360 * WSLUA_CLASS_DEFINE must be used with a trailing ';'
361 * (a dummy typedef is used to be syntactically correct)
363 #define WSLUA_CLASS_DEFINE(C,check_code) \
364 WSLUA_CLASS_DEFINE_BASE(C,check_code,NULL)
366 #define WSLUA_CLASS_DEFINE_BASE(C,check_code,retval) \
367 C to##C(lua_State* L, int idx) { \
368 C* v = (C*)lua_touserdata (L, idx); \
369 if (!v) luaL_error(L, "bad argument %d (%s expected, got %s)", idx, #C, lua_typename(L, lua_type(L, idx))); \
370 return v ? *v : retval; \
372 C check##C(lua_State* L, int idx) { \
374 luaL_checktype(L,idx,LUA_TUSERDATA); \
375 p = (C*)luaL_checkudata(L, idx, #C); \
377 return p ? *p : retval; \
379 C* push##C(lua_State* L, C v) { \
381 luaL_checkstack(L,2,"Unable to grow stack\n"); \
382 p = (C*)lua_newuserdata(L,sizeof(C)); *p = v; \
383 luaL_getmetatable(L, #C); lua_setmetatable(L, -2); \
386 gboolean is##C(lua_State* L,int i) { \
388 if(!lua_isuserdata(L,i)) return FALSE; \
389 p = lua_touserdata(L, i); \
390 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
391 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
393 return p ? TRUE : FALSE; \
395 C shift##C(lua_State* L,int i) { \
397 if(!lua_isuserdata(L,i)) return retval; \
398 p = (C*)lua_touserdata(L, i); \
399 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
400 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
402 if (p) { lua_remove(L,i); return *p; }\
407 typedef struct _wslua_attribute_table {
408 const gchar *fieldname;
409 lua_CFunction getfunc;
410 lua_CFunction setfunc;
411 } wslua_attribute_table;
412 extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, gboolean is_getter);
414 #define WSLUA_TYPEOF_FIELD "__typeof"
418 /* temporary transition macro to reduce duplication in WSLUA_REGISTER_xxx. */
419 #define WSLUA_REGISTER_GC(C) \
420 luaL_getmetatable(L, #C); \
421 /* add the '__gc' metamethod with a C-function named Class__gc */ \
422 /* this will force ALL wslua classes to have a Class__gc function defined, which is good */ \
423 lua_pushcfunction(L, C ## __gc); \
424 lua_setfield(L, -2, "__gc"); \
425 /* pop the metatable */ \
428 #define __WSLUA_REGISTER_META(C, ATTRS) { \
429 const wslua_class C ## _class = { \
431 .instance_meta = C ## _meta, \
434 wslua_register_classinstance_meta(L, &C ## _class); \
435 WSLUA_REGISTER_GC(C); \
438 #define WSLUA_REGISTER_META(C) __WSLUA_REGISTER_META(C, NULL)
439 #define WSLUA_REGISTER_META_WITH_ATTRS(C) \
440 __WSLUA_REGISTER_META(C, C ## _attributes)
442 #define __WSLUA_REGISTER_CLASS(C, ATTRS) { \
443 const wslua_class C ## _class = { \
445 .class_methods = C ## _methods, \
446 .class_meta = C ## _meta, \
447 .instance_methods = C ## _methods, \
448 .instance_meta = C ## _meta, \
451 wslua_register_class(L, &C ## _class); \
452 WSLUA_REGISTER_GC(C); \
455 #define WSLUA_REGISTER_CLASS(C) __WSLUA_REGISTER_CLASS(C, NULL)
456 #define WSLUA_REGISTER_CLASS_WITH_ATTRS(C) \
457 __WSLUA_REGISTER_CLASS(C, C ## _attributes)
459 #define WSLUA_INIT(L) \
461 wslua_register_classes(L); \
462 wslua_register_functions(L);
466 #define WSLUA_FUNCTION extern int
467 /* This is for functions intended only to be used in init.lua */
468 #define WSLUA_INTERNAL_FUNCTION extern int
470 #define WSLUA_REGISTER_FUNCTION(name) { lua_pushcfunction(L, wslua_## name); lua_setglobal(L, #name); }
472 #define WSLUA_REGISTER extern int
474 #define WSLUA_METHOD static int
475 #define WSLUA_CONSTRUCTOR static int
476 #define WSLUA_ATTR_SET static int
477 #define WSLUA_ATTR_GET static int
478 #define WSLUA_METAMETHOD static int
480 #define WSLUA_METHODS static const luaL_Reg
481 #define WSLUA_META static const luaL_Reg
482 #define WSLUA_CLASS_FNREG(class,name) { #name, class##_##name }
483 #define WSLUA_CLASS_FNREG_ALIAS(class,aliasname,name) { #aliasname, class##_##name }
484 #define WSLUA_CLASS_MTREG(class,name) { "__" #name, class##__##name }
486 #define WSLUA_ATTRIBUTES static const wslua_attribute_table
487 /* following are useful macros for the rows in the array created by above */
488 #define WSLUA_ATTRIBUTE_RWREG(class,name) { #name, class##_get_##name, class##_set_##name }
489 #define WSLUA_ATTRIBUTE_ROREG(class,name) { #name, class##_get_##name, NULL }
490 #define WSLUA_ATTRIBUTE_WOREG(class,name) { #name, NULL, class##_set_##name }
492 #define WSLUA_ATTRIBUTE_FUNC_SETTER(C,field) \
493 static int C##_set_##field (lua_State* L) { \
494 C obj = check##C (L,1); \
495 if (! lua_isfunction(L,-1) ) \
496 return luaL_error(L, "%s's attribute `%s' must be a function", #C , #field ); \
497 if (obj->field##_ref != LUA_NOREF) \
498 /* there was one registered before, remove it */ \
499 luaL_unref(L, LUA_REGISTRYINDEX, obj->field##_ref); \
500 obj->field##_ref = luaL_ref(L, LUA_REGISTRYINDEX); \
503 /* silly little trick so we can add a semicolon after this macro */ \
504 typedef void __dummy##C##_set_##field
506 #define WSLUA_ATTRIBUTE_GET(C,name,block) \
507 static int C##_get_##name (lua_State* L) { \
508 C obj = check##C (L,1); \
512 /* silly little trick so we can add a semicolon after this macro */ \
513 typedef void __dummy##C##_get_##name
515 #define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_GETTER(C,name,member) \
516 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushboolean(L, obj->member );})
518 #define WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(C,name,member) \
519 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushnumber(L,(lua_Number)(obj->member));})
521 #define WSLUA_ATTRIBUTE_NUMBER_GETTER(C,member) \
522 WSLUA_ATTRIBUTE_NAMED_NUMBER_GETTER(C,member,member)
524 #define WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(C,name,block) \
525 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushnumber(L,(lua_Number)(block));})
527 #define WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,name,member) \
528 WSLUA_ATTRIBUTE_GET(C,name, { \
529 lua_pushstring(L,obj->member); /* this pushes nil if obj->member is null */ \
532 #define WSLUA_ATTRIBUTE_STRING_GETTER(C,member) \
533 WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,member,member)
535 #define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(C,name,member,option) \
536 WSLUA_ATTRIBUTE_GET(C,name, { \
538 if ((obj->member) && (obj->member->len > 0)) { \
539 if (wtap_block_get_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, &str) == WTAP_OPTTYPE_SUCCESS) { \
540 lua_pushstring(L,str); \
546 * XXX - we need to support Lua programs getting instances of a "multiple
547 * allowed" option other than the first option.
549 #define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER(C,name,member,option) \
550 WSLUA_ATTRIBUTE_GET(C,name, { \
552 if ((obj->member) && (obj->member->len > 0)) { \
553 if (wtap_block_get_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, &str) == WTAP_OPTTYPE_SUCCESS) { \
554 lua_pushstring(L,str); \
559 #define WSLUA_ATTRIBUTE_SET(C,name,block) \
560 static int C##_set_##name (lua_State* L) { \
561 C obj = check##C (L,1); \
565 /* silly little trick so we can add a semicolon after this macro */ \
566 typedef void __dummy##C##_set_##name
568 #define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER(C,name,member) \
569 WSLUA_ATTRIBUTE_SET(C,name, { \
570 if (! lua_isboolean(L,-1) ) \
571 return luaL_error(L, "%s's attribute `%s' must be a boolean", #C , #name ); \
572 obj->member = lua_toboolean(L,-1); \
575 /* to make this integral-safe, we treat it as int32 and then cast
576 Note: This will truncate 64-bit integers (but then Lua itself only has doubles */
577 #define WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(C,name,member,cast) \
578 WSLUA_ATTRIBUTE_SET(C,name, { \
579 if (! lua_isnumber(L,-1) ) \
580 return luaL_error(L, "%s's attribute `%s' must be a number", #C , #name ); \
581 obj->member = (cast) wslua_togint32(L,-1); \
584 #define WSLUA_ATTRIBUTE_NUMBER_SETTER(C,member,cast) \
585 WSLUA_ATTRIBUTE_NAMED_NUMBER_SETTER(C,member,member,cast)
587 #define WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,member,need_free) \
588 static int C##_set_##field (lua_State* L) { \
589 C obj = check##C (L,1); \
591 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
592 s = g_strdup(lua_tostring(L,-1)); \
594 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
596 if (obj->member != NULL && need_free) \
597 g_free((void*) obj->member); \
601 /* silly little trick so we can add a semicolon after this macro */ \
602 typedef void __dummy##C##_set_##field
604 #define WSLUA_ATTRIBUTE_STRING_SETTER(C,field,need_free) \
605 WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,field,need_free)
607 #define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(C,field,member,option) \
608 static int C##_set_##field (lua_State* L) { \
609 C obj = check##C (L,1); \
611 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
612 s = g_strdup(lua_tostring(L,-1)); \
614 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
616 if ((obj->member) && (obj->member->len > 0)) { \
617 wtap_block_set_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, s, strlen(s)); \
622 /* silly little trick so we can add a semicolon after this macro */ \
623 typedef void __dummy##C##_set_##field
625 #define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER(C,field,member,option) \
626 static int C##_set_##field (lua_State* L) { \
627 C obj = check##C (L,1); \
629 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
630 s = g_strdup(lua_tostring(L,-1)); \
632 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
634 if ((obj->member) && (obj->member->len > 0)) { \
635 wtap_block_set_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, s, strlen(s)); \
640 /* silly little trick so we can add a semicolon after this macro */ \
641 typedef void __dummy##C##_set_##field
643 #define WSLUA_ERROR(name,error) { luaL_error(L, "%s%s", #name ": " ,error); }
644 #define WSLUA_ARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_ARG_ ## name ## _ ## attr, #name ": " error); }
645 #define WSLUA_OPTARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_OPTARG_##name##_ ##attr, #name ": " error); }
647 #define WSLUA_REG_GLOBAL_BOOL(L,n,v) { lua_pushboolean(L,v); lua_setglobal(L,n); }
648 #define WSLUA_REG_GLOBAL_STRING(L,n,v) { lua_pushstring(L,v); lua_setglobal(L,n); }
649 #define WSLUA_REG_GLOBAL_NUMBER(L,n,v) { lua_pushnumber(L,v); lua_setglobal(L,n); }
651 #define WSLUA_RETURN(i) return (i)
653 #define WSLUA_API extern
655 /* empty macro arguments trigger ISO C90 warnings, so do this */
658 #define FAIL_ON_NULL(s) if (! *p) luaL_argerror(L,idx,"null " s)
660 #define FAIL_ON_NULL_OR_EXPIRED(s) if (!*p) { \
661 luaL_argerror(L,idx,"null " s); \
662 } else if ((*p)->expired) { \
663 luaL_argerror(L,idx,"expired " s); \
666 /* Clears or marks references that connects Lua to Wireshark structures */
667 #define CLEAR_OUTSTANDING(C, marker, marker_val) void clear_outstanding_##C(void) { \
668 while (outstanding_##C->len) { \
669 C p = (C)g_ptr_array_remove_index_fast(outstanding_##C,0); \
671 if (p->marker != marker_val) \
672 p->marker = marker_val; \
679 #define WSLUA_CLASS_DECLARE(C) \
680 extern C to##C(lua_State* L, int idx); \
681 extern C check##C(lua_State* L, int idx); \
682 extern C* push##C(lua_State* L, C v); \
683 extern int C##_register(lua_State* L); \
684 extern gboolean is##C(lua_State* L,int i); \
685 extern C shift##C(lua_State* L,int i)
688 /* Throws a Wireshark exception, catchable via normal exceptions.h routines. */
689 #define THROW_LUA_ERROR(...) \
690 THROW_FORMATTED(DissectorError, __VA_ARGS__)
692 /* Catches any Wireshark exceptions in code and convert it into a LUA error.
693 * Normal restrictions for TRY/CATCH apply, in particular, do not return! */
694 #define WRAP_NON_LUA_EXCEPTIONS(code) \
696 volatile gboolean has_error = FALSE; \
700 lua_pushstring(L, GET_MESSAGE); \
703 if (has_error) { lua_error(L); } \
707 extern packet_info* lua_pinfo;
708 extern TreeItem lua_tree;
709 extern tvbuff_t* lua_tvb;
710 extern gboolean lua_initialized;
711 extern int lua_dissectors_table_ref;
712 extern int lua_heur_dissectors_table_ref;
714 WSLUA_DECLARE_CLASSES()
715 WSLUA_DECLARE_FUNCTIONS()
717 extern lua_State* wslua_state(void);
720 /* wslua_internals.c */
722 * @brief Type for defining new classes.
724 * A new class is defined as a Lua table type. Instances of this class are
725 * created through pushXxx which sets the appropriate metatable.
727 typedef struct _wslua_class {
728 const char *name; /**< Class name that is exposed to Lua code. */
729 const luaL_Reg *class_methods; /**< Methods for the static class (optional) */
730 const luaL_Reg *class_meta; /**< Metatable for the static class (optional) */
731 const luaL_Reg *instance_methods; /**< Methods for class instances. (optional) */
732 const luaL_Reg *instance_meta; /**< Metatable for class instances (optional) */
733 const wslua_attribute_table *attrs; /**< Table of getters/setters for attributes on class instances (optional). */
735 void wslua_register_classinstance_meta(lua_State *L, const wslua_class *cls_def);
736 void wslua_register_class(lua_State *L, const wslua_class *cls_def);
738 extern int wslua__concat(lua_State* L);
739 extern gboolean wslua_toboolean(lua_State* L, int n);
740 extern gboolean wslua_checkboolean(lua_State* L, int n);
741 extern gboolean wslua_optbool(lua_State* L, int n, gboolean def);
742 extern lua_Integer wslua_tointeger(lua_State* L, int n);
743 extern int wslua_optboolint(lua_State* L, int n, int def);
744 extern const char* wslua_checklstring_only(lua_State* L, int n, size_t *l);
745 extern const char* wslua_checkstring_only(lua_State* L, int n);
746 extern void wslua_setfuncs(lua_State *L, const luaL_Reg *l, int nup);
747 extern const gchar* wslua_typeof_unknown;
748 extern const gchar* wslua_typeof(lua_State *L, int idx);
749 extern gboolean wslua_get_table(lua_State *L, int idx, const gchar *name);
750 extern gboolean wslua_get_field(lua_State *L, int idx, const gchar *name);
751 extern int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data);
752 extern int heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data);
753 extern expert_field* wslua_get_expert_field(const int group, const int severity);
754 extern void wslua_prefs_changed(void);
755 extern void proto_register_lua(void);
756 extern GString* lua_register_all_taps(void);
757 extern void wslua_prime_dfilter(epan_dissect_t *edt);
758 extern gboolean wslua_has_field_extractors(void);
759 extern void lua_prime_all_fields(proto_tree* tree);
761 extern int Proto_commit(lua_State* L);
763 extern TreeItem create_TreeItem(proto_tree* tree, proto_item* item);
765 extern void clear_outstanding_FuncSavers(void);
767 extern void Int64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittleEndian);
768 extern int Int64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian);
769 extern void UInt64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittleEndian);
770 extern int UInt64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian);
772 extern Tvb* push_Tvb(lua_State* L, tvbuff_t* tvb);
773 extern int push_wsluaTvb(lua_State* L, Tvb t);
774 extern gboolean push_TvbRange(lua_State* L, tvbuff_t* tvb, int offset, int len);
775 extern void clear_outstanding_Tvb(void);
776 extern void clear_outstanding_TvbRange(void);
778 extern Pinfo* push_Pinfo(lua_State* L, packet_info* p);
779 extern void clear_outstanding_Pinfo(void);
780 extern void clear_outstanding_Column(void);
781 extern void clear_outstanding_Columns(void);
782 extern void clear_outstanding_PrivateTable(void);
784 extern int get_hf_wslua_text(void);
785 extern TreeItem push_TreeItem(lua_State *L, proto_tree *tree, proto_item *item);
786 extern void clear_outstanding_TreeItem(void);
788 extern FieldInfo* push_FieldInfo(lua_State *L, field_info* f);
789 extern void clear_outstanding_FieldInfo(void);
791 extern void wslua_print_stack(char* s, lua_State* L);
793 extern void wslua_init(register_cb cb, gpointer client_data);
794 extern void wslua_early_cleanup(void);
795 extern void wslua_cleanup(void);
797 extern tap_extractor_t wslua_get_tap_extractor(const gchar* name);
798 extern int wslua_set_tap_enums(lua_State* L);
800 extern ProtoField wslua_is_field_available(lua_State* L, const char* field_abbr);
802 extern char* wslua_get_actual_filename(const char* fname);
804 extern int wslua_bin2hex(lua_State* L, const guint8* data, const guint len, const gboolean lowercase, const gchar* sep);
805 extern int wslua_hex2bin(lua_State* L, const char* data, const guint len, const gchar* sep);
806 extern int luaopen_rex_glib(lua_State *L);
808 extern const gchar* get_current_plugin_version(void);
809 extern void clear_current_plugin_version(void);
811 extern int wslua_deregister_heur_dissectors(lua_State* L);
812 extern int wslua_deregister_protocols(lua_State* L);
813 extern int wslua_deregister_dissector_tables(lua_State* L);
814 extern int wslua_deregister_listeners(lua_State* L);
815 extern int wslua_deregister_fields(lua_State* L);
816 extern int wslua_deregister_filehandlers(lua_State* L);
817 extern void wslua_deregister_menus(void);
822 * Editor modelines - https://www.wireshark.org/tools/modelines.html
827 * indent-tabs-mode: nil
830 * vi: set shiftwidth=4 tabstop=8 expandtab:
831 * :indentSize=4:tabSize=8:noTabs=true: