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

  • Home
  • SEARCH
  • 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 9234055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:41:59+00:00 2026-06-18T06:41:59+00:00

I am running Lua with a C++ library via swig. When a swig runtime

  • 0

I am running Lua with a C++ library via swig. When a swig runtime error occurs I would like to know the line which caused the problem. The error message I receive does not have this information.

How can I find which line in the Lua code triggered the error?

For example suppose I have a swig function “swigstringcount” and it takes a string:

local n=4
local m=swigstringcount(n)
print (m,n)

This (obviously wrong) code produces an error on line two. Currently all I get is

error:SWIG_RuntimeError: swigstringcount requires a string

I want it to tell me that line 2 produced the error, like standard Lua error messages.

  • 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-06-18T06:42:00+00:00Added an answer on June 18, 2026 at 6:42 am

    Based on this method for getting debug info from the Lua C API I’ve put together a (slightly messy) example of how you can integrate that into a SWIG interface:

    %module test
    
    %{
    #undef SWIG_fail_arg
    #define SWIG_fail_arg(func_name,argnum,type) \
      {lua_Debug ar;\
      lua_getstack(L, 1, &ar);\
      lua_getinfo(L, "nSl", &ar);\
      lua_pushfstring(L,"Error (%s:%d) in %s (arg %d), expected '%s' got '%s'",\
      ar.source,ar.currentline,func_name,argnum,type,SWIG_Lua_typename(L,argnum));\
      goto fail;}
    %}
    
    %include <std_string.i>
    
    %inline %{
    void func(const std::string& str) {}
    %}
    

    This basically replaces the default SWIG_fail_arg macro with a modified one that gets and prints some debug info.

    I tested it with the latest SWIG trunk (I think you might be using an older version since the text I see didn’t quite match), but I was able to do:

    Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
    > require('test')
    > local n=4
    > test.func(n)
    Error (=stdin:1) in func (arg 1), expected 'std::string const &' got 'nil'
    stack traceback:
            [C]: in function 'func'
            stdin:1: in main chunk
            [C]: ?
    

    I seem to have more debug info (i.e. a full stack trace) there already though.

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

Sidebar

Related Questions

Running the following line in my script gives me a Permission denied error: $config_out
It is possible to create a Lua module which returns multiple results via the
I was wondering whether Lua has any preemptive multitasking facilities built-in. I would like
I'm trying to wrap a class from a library I'm using in Lua. Specifially,
I'm running Lighttpd on Cygwin. I have a Lua CGI script that calls a
I have embedded Lua in an Objective-C application using LuaObjCBridge. I need to know
I would like to build a live coding framework. I should explain what is
I'm using Electro in Lua for some 3D simulations, and I'm running in to
I've begun running into slight issues with certain functions that I've bound to lua
I have an app written in Lua with wxLua. While this app is running,

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.