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 6200561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:23:23+00:00 2026-05-24T04:23:23+00:00

I have a C++ program that I have bound to Lua using luabind. I

  • 0

I have a C++ program that I have bound to Lua using luabind. I am currently testing the error handling methods that lua and luabind have to offer in order to help with debugging the lua scripts down the road. The objective is to have luabind or lua throw an exception when syntax errors and programming mistakes arise so that I can debug and correct them.

Right now, the problem is that the script below just stops executing without any error messages or exceptions being thrown, so in a larger program I would have no idea where the problem would be or even if there was a problem in the first place.

Here are the relevant snippets:

Lua: (start.lua)

--complete file shown, this is meant to test the error handling of the C++ program
print("This is valid")
print(1234)
bad_function()
a = "meow"
b = 7
c = a + b

C++:

Engine *callbackEngine;
int theCallback(lua_State *L) //This is so I can use my own function as an
                              //exception handler, pcall_log()
{
    return callbackEngine->pcall_log(L);
}

void Engine::Run()
{
    luabind::set_pcall_callback(&theCallback); //my own callback function, 
                                               //redirects to
                                               //pcall_log() below
try {
    luaL_dofile(L, "scripts/start.lua");
}
catch(luabind::error &sError) { //This never gets executed, noted by breakpoints
    theCallback(L);
}
//etc...code not shown

int Engine::pcall_log(lua_State *L)
{
    lua_Debug d;
    lua_getstack( L,1,&d);
    lua_getinfo( L, "Sln", &d);
    lua_pop(L, 1);
    stringstream ss;
    ss.clear();
    ss.str("");
    ss << d.short_src;
    ss << ": ";
    ss << d.currentline;
    ss << ": ";
    if ( d.name != 0)
    {
        ss << d.namewhat;
        ss << " ";
        ss << d.name;
        ss << ") ";
    }
    ss << lua_tostring(L, -1);
    logger->log(ss.str().c_str(),ELL_ERROR);
    return 1;
}

Here is the output when run:

This is valid
1234

The script stops running instead of throwing an exception like I anticipated. Is there a way to control when lua throws an exception or another way to handle errors? I have the logging function setup to produce debugging information, but breakpoints reveal that the catch statement above is not getting executed.

Thank you!

  • 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-24T04:23:24+00:00Added an answer on May 24, 2026 at 4:23 am

    If you want to load a Lua script through Luabind, then you can’t use luaL_dofile or other regular Lua functions to do it. You have to use Luabind functions. So that would look something like this:

    namespace lb = luabind;
    int luaError = luaL_loadfile(pLuaState, "scripts/start.lua");
    //Check for errors
    
    lb::object compiledScript(lb::from_stack(pLuaState, -1));
    lb::call_function<void>(compiledScript); //Call the script.
    
    lua_pop(pLuaState, 1); //Remove the script from the stack. It's stored in our luabind::object
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that monitors debug messages and I have tried using a
I have a high CPU/memory bound task that I would like my Scala program
I have a program that searches a file (numbers.dat) using a binary search and
I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that spits out an Excel workbook in Excel 2003 XML
I have a program that will calculate the minimal area taken by fitting rectangles
I have a program that runs osql.exe from microsoft sql server tools directory and
I have a program that I need to run under *nix and windows. because

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.