Get current line and file from C++


#1

Is there any way to get the current line of code that ChaiScript is executing from C++? For example, this is what you would do in Lua:

lua_Debug ar;
lua_getstack(L, 1, &ar);
lua_getinfo(L, "Sl", &ar);
int line = ar.currentline;
std::string file = ar.source;

(code partially ripped from here)


#2

That would be useful for custom error report in editors. I am working on something like this inside my game-specific editor.


#3

It would be possible if you added your own Tracer object in the current development branch.

This is all very experimental right now. But if I were to actively track the current location being executed it would add unnecessary overhead, but if that’s a feature you need, the Tracer could be a good option.

Here is an example from the unittests https://github.com/ChaiScript/ChaiScript/blob/develop/unittests/compiled_tests.cpp#L991-L1016

-Jason