ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Is there a way to get caller function name? (https://www.esoui.com/forums/showthread.php?t=7381)

Taonnor 09/25/17 08:35 AM

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?

Ayantir 09/25/17 08:40 AM

trigger an error and the backtrace will be shown ?

d(I'm a stupid dev who forget quotes)

Dolgubon 09/25/17 09:18 AM

Or err() if you don't want to halt.it. ( I think that is the right function name)

Taonnor 09/25/17 09:22 AM

I will try both, but @Ayantir your solution looks very dirty. :)

BTW you have a PM Ayantir

Dolgubon 09/25/17 10:20 AM

My method is basically the same as Ayantir's. Also, I checked and it's actually error()

Taonnor 09/25/17 02:00 PM

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()"

Ayantir 09/25/17 02:32 PM

It's Lua embedded into a sandbox of a MMORPG, not Java or C#, you won't have all the fancy things.

Dolgubon 09/25/17 02:36 PM

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!'

votan 09/25/17 11:35 PM

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. ...

sirinsidiator 09/26/17 06:55 AM

http://www.esoui.com/downloads/info1210-sidTools.html
Quote:

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. :rolleyes:


All times are GMT -6. The time now is 06:09 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI