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

I notice that Swig provides a whole host of functions to allow for typecasting
I want to use swig for generation of read-only wrappers for a complex object.
SWIG compiles and install easily on AIX. Unfortunately, a simple SWIG hello world (which
The SWIG documentation explains how a variety of input types in C, like this:
Possible Duplicate: SWIG Java Retaining Class information of the objects bouncing from C++ Question
I used SWIG to generate a Perl module for a C++ program. I have
I'm using SWIG to wrap C++ objects for use in lua, and Im trying
I am using SWIG to pass numpy arrays from Python to C++ code: %include
I have used SWIG to bind a set of classes to lua. I know
I am using SWIG to access C++ code from Java. What is the easiest

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.