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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:26:14+00:00 2026-05-12T18:26:14+00:00

SWIG graciously provides the swig_type() function to get a string representation of the data

  • 0

SWIG graciously provides the swig_type() function to get a string representation of the data type of a passed userdata object. However, in the case of member fields, SWIG and Lua consider those to be simple “number” items and so prints only “number” instead of the data type’s name.

e.g.

typedef num_years int;

class Person
{
    public:
           Person * spouse;
           num_years   age;
};

in C++ would result in:

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio

> p = MyModule.Person();
> print(swig_type(p.spouse));
Person *
> print(swig_type(p.age));
number

Is there some back-door route I could take to determine member fields’ data types? I see that the get and set functions have the correct string representation of the number fields when validating arguments.

Thanks for any assistance!

  • 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-12T18:26:15+00:00Added an answer on May 12, 2026 at 6:26 pm

    SWIG-wrapped C++ objects are Lua userdata objects conforming to a particular set of rules. swig_type() works by peering into those userdata objects and retrieving the type name information that SWIG stored there. But age is represented directly, so there’s no type name field to look up, so swig_type() can’t do its magic. You can get what you want by making num_years an opaque class type that wraps an int (and which maybe defines some implicit conversions for ease of use in C++), but that’s a lot of work to go to for a dubious reward.

    The get and set functions work by an entirely different mechanism; they have the correct signature because SWIG stores it in the generated wrapper at compile time, copying from the interface file.

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

Sidebar

Related Questions

SWIG seems to be generating incorrect bindings for converting a struct field of type
I used SWIG for generating some native JNI function interface for Irrlicht C/C++ 3D
I have a SWIG generated function as follows: SWIGINTERN PyObject *_wrap_StrVector___getitem____SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args)
Per the SWIG Documentation (21.9.1 Default primitive type mappings), the C uint8_t is mapped
I notice that Swig provides a whole host of functions to allow for typecasting
I need to parse function headers from a .i file used by SWIG which
I'm trying to use SWIG to create a Octave function. But even the most
I am trying to get SWIG to work with Visual Studio and C#. I
I'm trying to figure out how to use SWIG to wrap a c++ function
I would like to wrap a C function with SWIG. The function takes a

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.