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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:09:08+00:00 2026-05-25T00:09:08+00:00

When I was working with Lua in C#, I would add attributes to the

  • 0

When I was working with Lua in C#, I would add attributes to the methods I wanted to register with Lua, something like this:

// place tile marker
[LuaExport("settilemarker")]
public void SetTileMarker(int x, int y)
{
    TileEditor.X = x;
    TileEditor.Y = y;
}

Then, I would use reflection at runtime to find all these functions and register them, automagically, with a short piece of code that didn’t have to be updated for each new function.
This could also be used to automatically build a list of all registered commands easily etc.

My question is, is there any way to do this with Lua in C++? Like some kind of macro, or something.
The information doesn’t have to be available at runtime, I just want the convenience of marking each function right where it’s defined and have them all be registered automatically, rather than having one long section somewhere of lua_register(..)s.

I’ve already found some tools that appear to be capable of generating code for this, but I was hoping there might be a way that doesn’t require any extra manual work besides hitting Build.
If not, I’ll have to investigate those tools further after all.

Using Visual Studio 2010, by the way.

  • 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-25T00:09:09+00:00Added an answer on May 25, 2026 at 12:09 am

    C and C++ do not have reflection. Therefore, any tool you use will require at least some manual work. You’re going to have to type something for every function you want to export, or you’re going to have to put the prototypes into a special location or something.

    There is a list of Lua binding utilities available. Some of them are semi-automated, including parsers that can read some subset of C++ and semi-automatically generate binding code for them. SWIG, toLua, and toLua++ are among these. Others require more work, but make it a bit easier to explicitly declare behavior (like ownership, etc).

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

Sidebar

Related Questions

Working with TCL and I'd like to implement something like the Strategy Pattern .
I am currently working on a project. One library I would like to consider
I'm working with Lua and C++ (using LuaWrapper) and I'm having trouble with something.
I'm working with large numbers that I can't have rounded off. Using Lua's standard
I'm lead dev for Bitfighter , and we're working with a mix of Lua
I'm working on a small project trying to integrate lua with c++. My problem
I'm fairly new to Lua, I've been working on trying to implement Lua scripting
I have a key => value table I'd like to sort in Lua. The
I'm working in lua, and i need to match 2 parts of a line
I am working on a game engine in C++ using Lua to define NPCs.

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.