Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get Current File/Line of Lua Code #97

Closed
codeaddicted opened this issue Oct 15, 2020 · 3 comments
Closed

get Current File/Line of Lua Code #97

codeaddicted opened this issue Oct 15, 2020 · 3 comments

Comments

@codeaddicted
Copy link

Hi,

me again. Short question. Is there any way to get the currently executed filename and line of the lua code when inside of a lua executed c++ function directly over kaguya or do i need to use this->_internalLua.state() and debug library stuff?

best Regards
Christoph

@satoren
Copy link
Owner

satoren commented Oct 17, 2020

kaguya doesn't have that feature
Use lua_getstack with lua_State.

@satoren
Copy link
Owner

satoren commented Oct 17, 2020

Example in my debugger code stack_info class

Usage

   // get all stack info(0 is top)
    std::vector<stack_info> ret;
    ret.push_back(stack_info(state, 0));
    while (ret.back().is_available()) {
      ret.push_back(stack_info(state, ret.size()));
    }
    ret.pop_back();

    printf("top stack line: %d source: %s",ret[0].currentline(), ret[0].source());

@codeaddicted
Copy link
Author

Hi,

thank you for the response. because i only need the current line and filename i solved it the following way:

int line;
std::string file;
lua_Debug ar;

lua_getstack(l.state(), 1, &ar);
lua_getinfo(l.state(), "Sl", &ar);

file = ar.source;
line = ar.currentline;

Best Regards
Christoph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants