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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:44:33+00:00 2026-05-28T17:44:33+00:00

I’m an absolute beginner when it comes to using both SWIG and lua, and

  • 0

I’m an absolute beginner when it comes to using both SWIG and lua, and a mediocre C++ developer, and I just don’t seem to understand how I can bind C++ classes with Lua.

My end goal is to have an instance of a class, pass it to my lua script which manipulates that object in a certain way, then I retrieve that object in c++ and do whatever else I want to do with it.

So… I’ve downloaded Lua and C++, compiled a few examples, I am able to run some lua script in my c++ program. So far so good.

Now, I’ve downloaded SWIG. I’m using VC2010 on Windows 7. From what I understand I’m suppose to create an interface file. So I’ve created one, example.i:

%module creature
class Creature
{
public:
    Creature(void);
    Creature(int id);
    ~Creature(void);

(...) the rest of my class here

(Just added %module creature to my Creature.h and saved it as creature.i). I ran SWIG using

 swig -c++ -lua creature.i

and got my creature.cxx file.

Now, I’ll probably embarrass myself now but… I don’t know what to do next. Am I suppose to build the output file somehow? How can I use it now? I’ve read here http://www.swig.org/Doc1.3/Lua.html that I need to link the generated file (*.cxx) with the rest of my code (so I do that by simply including the file in my project and adding the line #include “Creature.h”). But when I compile I get errors like

error C2065: 'LUA_GLOBALSINDEX' : undeclared identifier
error C2036: 'const luaL_reg *' : unknown size

I have also tried compiling it using MinGW but I get the same problem. It would be great if someone could show me an example or a step-by-step tutorial of how I can use these tools together, as I have a hard time grasping the whole idea. This is definitely due to my lack of understanding of the basics of how this should be used so please be gentle to a noob.

Any help will be much appreciated.

  • 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-28T17:44:34+00:00Added an answer on May 28, 2026 at 5:44 pm

    SWIG is a tool for linking scripting languages to C or C++ code. It works as a preprocess step: you run the SWIG executable on a .swig file, which produces a bit of C or C++ code. You then build that code into whatever project you want to do the linking to that scripting language for.

    SWIG’s Lua support is most certainly not compatible with Lua 5.2. Indeed, you will find very little code out there that is compatible with Lua 5.2. If you want to actually do something with Lua code, stick with 5.1 at least for the time being.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.