Is there a simple way to get the name of the current class I am in?

I would like to be able to programmatically retrieve the name of the current class I am in. Is there a straightforward way to achieve this?

In passing, if getting the name of the current function is possible, that would be great as well.

function myFunc()
    print(debug.getinfo(1, "n").name);


I suspect the same will work for Class functions — but the name you get will be qualified with the class name (Class.func). Though I’m not sure about this.

(Adapted from Stackoverflow:

@Simeon, thanks so much!

I had wondered how to do this also… I tried @Simeon’s code in a class function, and got the right name with:

debug.getinfo(2, "n").name

Is there a way to get the name of the instance of the class?

I’ve tried this solution but the only thing I get is e function name. does it exist a way to obtain also the class name?

Hi @shrike, when I used a 2 instead of a 1 as above I got the class name.

Hi @Fred, I’ve tried and using 2 it works, but only with derived class.