Quantcast Is there a way to get caller function name? - ESOUI
Thread Tools Display Modes
09/25/17, 08:35 AM   #1
Taonnor
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 7
Is there a way to get caller function name?

Hey everyone,

i'm looking for a simple way to get the caller name of function for a log trace method for debugging my addons.

I tried many ways and it should not possible to get the information via "debug.getinfo". The function seems to disabled in LUA/ESO context. So is there another way to get the caller informations or 'im doing something wrong?
  Reply With Quote
09/25/17, 08:40 AM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,022
trigger an error and the backtrace will be shown ?

d(I'm a stupid dev who forget quotes)
__________________
Obsessive Compulsive Coder

My little french Guild: Cercle de l'Eveil
  Reply With Quote
09/25/17, 09:18 AM   #3
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 314
Or err() if you don't want to halt.it. ( I think that is the right function name)
  Reply With Quote
09/25/17, 09:22 AM   #4
Taonnor
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 7
I will try both, but @Ayantir your solution looks very dirty.

BTW you have a PM Ayantir
  Reply With Quote
09/25/17, 10:20 AM   #5
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 314
My method is basically the same as Ayantir's. Also, I checked and it's actually error()
  Reply With Quote
09/25/17, 02:00 PM   #6
Taonnor
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 7
All solutions does not help. I only want a debug message to chat with caller function, without anoying type the function name as string into the message. The error() function throws an assertion, wich ends into an UI error.

For example
Lua Code:
  1. function callerFunction()
  2.    trace()
  3. end
will give this message into chat -> "[time] callerFunction()"

Last edited by Taonnor : 09/25/17 at 02:03 PM.
  Reply With Quote
09/25/17, 02:32 PM   #7
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,022
It's Lua embedded into a sandbox of a MMORPG, not Java or C#, you won't have all the fancy things.
__________________
Obsessive Compulsive Coder

My little french Guild: Cercle de l'Eveil
  Reply With Quote
09/25/17, 02:36 PM   #8
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 314
Well, I suppose if you want to be really fancy, you can do local _, errorMessage = pcall(function()error()end) and then make a function to parse errorMessage but the simplest way is just read the error message, and if you do, you'll see 'hey this thing does give me a trace!'
  Reply With Quote
09/25/17, 11:35 PM   #9
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 458
Lua Code:
  1. local function GetAddon()
  2.     local addOn
  3.     local function errornous() addOn = 'a' + 1 end
  4.     local function errorHandler(err) addOn = string.match(err, "'GetAddon'.+user:/AddOns/(.-:.-):") end
  5.     xpcall(errornous, errorHandler)
  6.     return addOn
  7. end
Lua Code:
  1. ...
  2. d(GetAddon())
  3. ...
__________________
@votan73 (EU - megaserver)
  Reply With Quote
09/26/17, 06:55 AM   #10
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,123
http://www.esoui.com/downloads/info1210-sidTools.html
trace(message[, callback])
Prints a message and stacktrace to chat via d() or hands the array with the stacktrace to an optional callback function instead
Just saying.
__________________
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Is there a way to get caller function name?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off