From 51940817913b282f6f265a5ee1a1ab0c1d6ee5ff Mon Sep 17 00:00:00 2001 From: Dorian Wouters Date: Mon, 1 Aug 2016 15:24:05 +0200 Subject: [PATCH] First commit --- .gitmodules | 3 +++ README.md | 31 +++++++++++++++++++++++++++++++ StackTracePlus | 1 + init.lua | 29 +++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 .gitmodules create mode 100644 README.md create mode 160000 StackTracePlus create mode 100644 init.lua diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f93e5a7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "StackTracePlus"] + path = StackTracePlus + url = https://github.com/ignacio/StackTracePlus.git diff --git a/README.md b/README.md new file mode 100644 index 0000000..1768bec --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# StackTracePlus Minetest mod + +StackTracePlus is a Lua module that extends `debug.traceback` to include more +call frame information such as local and globals, locals and parameters +dumps. + +This mod merely plugs this module in and replaces `debug.traceback` with +StackTracePlus's traceback dump routine. + +# Installing + +This repository uses git submodules. + +Clone this repo either recursively (`--recursive`) or as usual, but make sure +to `git submodule update --init` afterwards; it must go into the `mods` +directory. + +## Mod security + +This mod modifies the global `debug` table which is not accessible by normal +mods when mod security is enabled. + +If you have enabled mod security (`secure.enable_security` is `true`), then you +must whitelist this mod in `minetest.conf`'s `secure.trusted_mods` config +entry. + +# License + +WTFPL / CC0 / Public Domain. + +StackTracePlus is distributed under the MIT license. diff --git a/StackTracePlus b/StackTracePlus new file mode 160000 index 0000000..9b4aef9 --- /dev/null +++ b/StackTracePlus @@ -0,0 +1 @@ +Subproject commit 9b4aef95854ad0cf549850cee6dbd0fef5a82bf6 diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..97a1f83 --- /dev/null +++ b/init.lua @@ -0,0 +1,29 @@ +local secenv = _G +local modname = minetest.get_current_modname() +local sec = (minetest.setting_get('secure.enable_security') == 'true') +local ie +if sec then + ie = minetest.request_insecure_environment() + if ie == nil then + error("Mod security is on but " .. modname .. " is not whitelisted as a secure mod") + end +end + +if sec then + string, io, debug, coroutine = ie.string, ie.io, ie.debug, ie.coroutine +end + +local STP = dofile(minetest.get_modpath(modname) .. '/StackTracePlus/src/StackTracePlus.lua') +-- Remove string/table dump length limits +STP.max_tb_output_len = math.huge + +if sec then + ie.debug.traceback = STP.stacktrace + -- StackTracePlus caches the following modules, reset them to the original ones to + -- avoid leaking them + string, io, debug, coroutine = secenv.string, secenv.io, secenv.debug, secenv.coroutine + ie = nil +end +debug.traceback = STP.stacktrace + +minetest.log('action', "[" .. modname .. "] replaced debug.traceback")