summaryrefslogtreecommitdiff
path: root/epan/wslua/wslua_internals.c
AgeCommit message (Collapse)AuthorFilesLines
2016-10-18wslua: prepare for split class/instance (meta)methodsPeter Wu1-206/+289
Previously the metatables for classes were the same for the class and its instances. This results in issues like calling __gc on the class table on exit. Make it possible to declare separate class methods (functions) and instance methods. Observe that all attributes apply to the instances only, so make these just available on the instance. The attribute/methods lookup method (via __index/__newindex) have been rewritten to use upvalues, removing the technical need for the properties __getters/__setters/__methods. The "lua globals" test still checks for these, but it could be removed in the future. To fix bug 12968, the __gc method is removed from the class method. Future patches should remove the WSLUA_REGISTER_CLASS, WSLUA_REGISTER_META and WSLUA_REGISTER_ATTRIBUTES macros completely and create split class functions/methods (such that __call for an instance cannot accidentally be invoked on the class). Removed duplicate "fragmented" property from Pinfo (which triggered an error) and replaced exit() by g_error() for debugger friendliness. Remove lua_shiftstring since checkstring always returns non-NULL. Bug: 12968 Change-Id: I57f8a93d08bb84c79b0e94cf2c82d8402fc16646 Reviewed-on: https://code.wireshark.org/review/18026 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Balint Reczey <balint@balintreczey.hu>
2016-10-18wslua: add support for negative indicesPeter Wu1-11/+21
Internal change, this allows use of negative indices for lua_rawgetfield/lua_rawsetfield convenience functions and is closer to lua_getfield/lua_setfield semantics in terms of indices. Add lua_absindex for compatibility with Lua 5.1 (do not bother exporting it yet since it is only used in this file, also do not rename it since it is the same functionality with no Wireshark-specific changes.) Change-Id: I322954ef461164ec514ed9f034ae2691775e67da Reviewed-on: https://code.wireshark.org/review/18025 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-07-25Fix checkAPI.pl warnings about printfMichael Mann1-2/+3
Many of the complaints from checkAPI.pl for use of printf are when its embedded in an #ifdef and checkAPI isn't smart enough to figure that out. The other (non-ifdef) use is dumping internal structures (which is a type of debug functionality) Add a "ws_debug_printf" macro for printf to pacify the warnings. Change-Id: I63610e1adbbaf2feffb4ec9d4f817247d833f7fd Reviewed-on: https://code.wireshark.org/review/16623 Reviewed-by: Michael Mann <mmann78@netscape.net> Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-02-13wslua*: Add editor modelines; Fix indentation, etc as needed.Bill Meier1-0/+13
Change-Id: I6df5d46f4b263104aa9cb6353cc987087cdb867e Reviewed-on: https://code.wireshark.org/review/7102 Reviewed-by: Bill Meier <wmeier@newsguy.com>
2015-01-23Use luaL_{check,opt}integer() rather than luaL_{check,opt}int().Guy Harris1-2/+2
Lua prior to 5.3 defined luaL_{check,opt}int() as macros wrapping luaL_{check,opt}integer() with a cast to int; Lua 5.3 doesn't. It sounds as if the Lua developers are deprecating luaL_{check,opt}int(): http://osdir.com/ml/general/2014-10/msg46568.html Change-Id: I2d0b649dcd57ede124f31d39f7945f342ae9b18f Reviewed-on: https://code.wireshark.org/review/6744 Petri-Dish: Guy Harris <guy@alum.mit.edu> Reviewed-by: Guy Harris <guy@alum.mit.edu> Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com> Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Tested-by: Hadriel Kaplan <hadrielk@yahoo.com>
2015-01-03Lua: replace deprecated functionsHadriel Kaplan1-2/+0
Remove deprecated functions from Lua API code: tvb_length and tvb_length_remaining. The calls to proto_tree_add_text() are left in, as I have no idea what to replace them with. The calls to ep_* are being left in, as they're removed by change-id I3d19a770e0fd77d996bdb6b61a76a722cc2bcd55. Bug: 10822 Change-Id: Ib0686f90be1edc892d3ecf401b91eb7484540b3e Reviewed-on: https://code.wireshark.org/review/6247 Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com> Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-10-16Fix some more "char is unsigned" issues, and a possible "char is signed" one.Guy Harris1-4/+4
C neither guarantees that char is signed nor that it's unsigned. Make the str_to_nibble tables arrays of gint8, to make sure they can hold numbers between 0 and 15 as well as -1. Cast gchar to guchar, not int, when using it as a subscript into that array, so that the subscripts are in the range 0 to 255, not -128 to 127. Change-Id: Ib85de5aa4e83ae9efd808c78ce3f86f45b4a3f2a Reviewed-on: https://code.wireshark.org/review/4734 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-04-04Remove $Id$ in wsluaAlexis La Goutte1-1/+1
Change-Id: I01052bb4c41a17e8289cc7ed1b465042c23b6d82 Reviewed-on: https://code.wireshark.org/review/957 Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-28Allow chained calls with Lua TreeItem functions, and fix a couple of minor ↵Hadriel Kaplan1-0/+48
errors. A common Lua idiom is to use chained calls, i.e. tree:foo():bar():choo(). This actually works for tree:add() because it returns the new child tree item which is then the one being applied to the next chained call. But it doesn't work beyond that for things like set_generated() and so on. So this commit fixes that. This also fixes the Lua tree:add() function for the FT_BOOL type to let it be a Lua boolean value. And it reverts a previous change to Struct.tohex() to allow coercion of the argument. Change-Id: I10f819d363163914ba320c87d4bedebe5b50cacf Reviewed-on: https://code.wireshark.org/review/851 Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-25Enhance Lua API doc generator and add more API infoHadriel Kaplan1-0/+108
This enhances the Lua API doc generator Perl script to handle meta-information in description comments, such as bold, italics, raw code, version info, etc. The supported markup and codes are documented in make-wsluarm.pl. It's not beautiful Perl code (I don't know Perl), and I'd rather do it using Lua, but I think keeping it Perl makes more sense in the long run. Change-Id: I477b3ebe770075dcea9ec52708e2d6fb5758d2f4 Reviewed-on: https://code.wireshark.org/review/802 Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-23Add Lua Struct.values() function, and prevent coercion in all Struct functionsHadriel Kaplan1-0/+14
This adds a Struct.values() function to get the number of values needed/returned with Struct.pack/unpack. It also changes the existing Struct functions such that they don't coerce a non-string argument into a string. (not preventing it confused a user on ask.wireshark.org) Change-Id: I93d5846105e55b67680e1c276a7286535c77b039 Reviewed-on: https://code.wireshark.org/review/790 Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-14Add Lua heuristic dissector supportHadriel Kaplan1-2/+38
This adds the ability for Lua scripts to register heuristic dissectors for any protocol that has registered a heuristic dissector list, such as UDP, TCP, and ~50 others. The Lua function can also establish a conversation tied to its Proto dissector, to avoid having to check the heuristics for the same flow. The example dissector in the testsuite has also been enhanced to include a heuristic dissector, to verify the functionality and provide an example implementation. Change-Id: Ie232602779f43d3418fe8db09c61d5fc0b59597a Reviewed-on: https://code.wireshark.org/review/576 Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-11Fix Bug 9870 'Lua: trying to call/get an invalid name results in a get-loop ↵Hadriel Kaplan1-6/+71
error' Due to the change I made previously for how methods are accessed, if you try to access one that doesn't exist (for example mistype it or whatever), you get an internal Lua error about a loop in table get, as opposed to the right error message about the field not existing. That's because I had set the class' metatable __index metamethod to point to the class table, which of course has the metatable with the __index metamethod, causing a lookup loop. Blech. Change-Id: I20d3717feadd45f652c2640e1671846184e7082d Reviewed-on: https://code.wireshark.org/review/593 Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-02-27Fix coverity warnings for all wslua files. (redux)Hadriel Kaplan1-2/+2
This fixes/addresses all the coverity warnings shown by the buildbots. (I hope) Change-Id: Ic2722df97c577d274e3cf3f0cbdca1902edde047 Reviewed-on: https://code.wireshark.org/review/423 Reviewed-by: Gerald Combs <gerald@wireshark.org>
2014-02-21Fix warnings - index() is declared as a function in some systems.Guy Harris1-4/+4
Change-Id: If9ee9f0decc0a9d7971095109e1012b015a9dc96 Reviewed-on: https://code.wireshark.org/review/282 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-02-21Cleanup on aisle 5: normalizes the Lua code to follow common schema/modelHadriel Kaplan1-0/+302
Over time the various wslua classes/functions have gotten moldy, with different ways of doing similar things. Some of it can't be changed without breaking backwards compatibility for Lua scripts, so I didn't do that. But I did what I could. The biggest change is a refactoring of how accessors/attributes are handled in the code, so that most of them work the same way using the same code. Specific changes made: * Added null/expired checking macro to class declarations for many classes * Removed extraneous pointer/expired checking, since checkFoo() does that already * Fixed "errors" reported by clang static analyzer; they were false positives, but it was easier to get it to stop complaining by changing the code * Moved internal wslua functions from wslua_utils.c into a new 'wslua_internals.c' file * Changed Listener/NSTime/Pinfo/Proto to use a common setter/getter accessor/attribute code model, instead of each of them doing their own * Fixed some API doc mistakes, mostly around attributes that were documented as read-only but were actually read-write Change-Id: Idddafc5fbd3545ebff29e063acc767e1c743a1a9 Reviewed-on: https://code.wireshark.org/review/271 Reviewed-by: Evan Huus <eapache@gmail.com> Tested-by: Evan Huus <eapache@gmail.com>