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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:34:10+00:00 2026-06-17T11:34:10+00:00

I have come upon a problem with binding C++ and Lua. I have implemented

  • 0

I have come upon a problem with binding C++ and Lua.
I have implemented a simple class system in Lua that makes me able to create an “instance” of a lua class from another lua file using

require 'classname'
m_newObj = classname() --"classname() creates a new instance

then I can access functions in m_newObj using

m_newObj:functionname(parameter)

This works perfectly fine, but I want to be able to access an instance of a lua class from C++ code.

Normally you can create access to lua functions in C++ using

lua_State* pL = luaL_newState();
...
lua_getglobal(pL, "functionName");
lua_call(pL,0,0);

But this only calls a function in a luafile, it does not call that specific function on a specific instance of the “class”.

So basically what I want to do is

  • get access to an instance of a lua class in C++
  • call functions on specific instance

The reason why I want to do this is because I’ve discovered that in performance it requires a lot more to use C++ functions in lua than using lua functions in C++, So to be able to use lua to extend entities without having the lua code call a lot of C++ functions I need to get access to lua classes in C++ instead of getting access to C++ classes in lua.

  • 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-17T11:34:11+00:00Added an answer on June 17, 2026 at 11:34 am

    Push your class onto the stack, lua_getfield() the function from it, and then copy your class back onto the top of the stack before calling the function. Something like this:

    int nresults = 1;                  // number of results from your Lua function
    
    lua_getglobal(L, "classname");
    lua_getfield(L, -1, "funcname");
    lua_pushvalue(L, -2);              // push a copy of the class to the top of the stack
    lua_call(L, 1, nresults);          // equivalent to classname.funcname(classname)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across an annoying problem. I have made a system and now
I have been trying for some time to create a class/series of classes that,
When have you ever personally come upon the halting problem in the field? This
I have come across the following basic Tree conflict: Local add, incoming add upon
I have come to know from book that for declaring a structure variable it
I have come across scripts that use: isset($_POST['submit']) as well as code that uses:
I have come across a strange problem which I would like to get your
I'm going through tutorials for doctrine and have come across a problem. Does the
I have a command line executable that is run from a C# class library.
I have a simple java program that creates a series of temporary files stored

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.