Garry's Mod Wiki

GM:OnLuaError

  GM:OnLuaError( string error, string realm, table stack, string name, string id )

Description

Called when a Lua error occurs.

On the server realm, this hook will only account for server-side errors, not client-side ones.

Arguments

1 string error
The error that occurred.
2 string realm
Where the Lua error took place, "client", or "server"
3 table stack
The Lua error stack trace
4 string name
Title of the addon that is creating the Lua errors.
5 string id
Steam Workshop ID of the addon creating Lua errors, if it is an addon.

Example

Replicate lua_error_url's functionality using the hook, while adding new values to the payload.

-- -- Called on logic errors such as nil functions being called or nil being used -- to index a table. -- hook.Add( "OnLuaError", "mock_lua_error_url", function( error, realm, stack, name, addon_id ) -- -- Send a POST request to the given URL with -- information relating to the error that could be useful for logging. -- http.Post( "https://example.com/report_lua_error.php", { error = error, stack = util.TableToJSON(stack, false), realm = realm, addon = addon_id or 0, gamemode = engine.ActiveGamemode(), gmv = VERSIONSTR, os = jit.os, -- -- New data extending upon lua_error_url for demonstrative purposes, -- not that these are very useful. -- addon_name = name, time = os.time(), player_count = player.GetCount() } ) end )