Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5931927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:45:48+00:00 2026-05-22T14:45:48+00:00

When lua code causes an exception, luabind will leave an error message on the

  • 0

When lua code causes an exception, luabind will leave an error message on the stack for me to collect. I am wondering how to guarantee that the lua stack will be in a sensible state after I have handled the exception:

  1. The examples I’ve found tells me to use luabind::from_stack(e.state(), -1). Won’t this leave the error message still on the stack? Shouldn’t I pop it?

  2. Is it sufficient to pop the error message from the stack? Does the error cause other garbage to be left on the stack?

How do I make sure that the lua state is good after an error has occurred?

This is what I’ve got:

try  {
    // Do lua-stuff here that causes an exception from lua
}
catch (const luabind::error& e) {
    luabind::object error_msg(luabind::from_stack(e.state(), -1));

    std::stringstream ss;
    ss << error_msg;

    throw my_own_exception_class(ss.str());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:45:49+00:00Added an answer on May 22, 2026 at 2:45 pm
    1. It will leave the error message on the stack. Whether you should pop it depends entirely on what you are doing with the stack next. If you don’t need the message anymore (since you saved it somewhere else) then pop it. If you are going to use it further down the catch chain, then leave it. The point is, you use the Lua stack to communicate with the Lua API, what you have on it depends entirely on what you want to tell the API.

    2. There are two ways to interpret “garbage” here:

      • As in “the Lua stack has compromised internal structure and any call to lua_XXX functions will SEGFAULT/crash/etc”. This should never happen no matter what C++ exceptions you throw around, it’s Luabind responsibility to guard against that. Any C++ exceptions are thrown and handled by Luabind as Lua itself is written in C and in its world there are no such things as exceptions.

      • As in “there are some values on the stack I no longer need”. There shouldn’t be garbage left on the stack. If you feel paranoid, feel free to clear the stack with lua_settop(0) before any chain of Lua API calls

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some C++ code that interacts with some Lua code. Basically, I want
I'm writing a C++/OOP wrapper for Lua. My code is: class LuaState { boost::shared_ptr<lua_State>
Could you, please, give a code snippet showing how to use Lua embedded in
Lua has a really nice no-parenthesis call syntax that coupled with function closures allow
In the following lua code: function interp(s, tab) return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)]
Consider the following Lua code: local var1, var2; Is var2 a local variable here?
is there any easy way to port Lua code to C#? The biggest problem
I have found myself having to turn a chunk of Lua code into a
I have a very simple little piece of Lua code, which I wrote while
I have a makefile that looks like: default: lua blah.lua Now, in Vim, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.