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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:57:04+00:00 2026-05-23T09:57:04+00:00

The luabind documentation says to call a Lua-derived virtual member from C++, you create

  • 0

The luabind documentation says to call a Lua-derived virtual member from C++, you create a wrapper class derived from luabind::wrap_base and call the function like so:

class BaseWrapper : public Base, public luabind::wrap_base
{
    public:
        virtual void foo()
        {
            call<void>("foo");
        }
};

So far so good – I have this much working.

But how do I implement BaseWrapper::foo() to call the overridden foo (on the Lua side) as a coroutine (using resume_function) instead of calling it directly with call?

This is how it’s done with non-member functions:

luabind::object func = luabind::globals(L)["bar"];
luabind::resume_function<void>(func);

I think what I need to know is how to get func for foo (as implemented by the Lua-derived class), and then my existing resume_function logic should work as-is.

  • 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-23T09:57:04+00:00Added an answer on May 23, 2026 at 9:57 am

    So I’ve figured out the answer to this problem. It seems that the simplest solution is to pass self from Lua when you construct the object and then look up the function from its table:

    On the C++ side:

    BaseWrapper::BaseWrapper(luabind::object self) : _self(self)
    { }
    
    virtual void BaseWrapper::foo()
    {
      luabind::object func = _self["foo"];
    
      /* now put func in coroutine scheduler queue and when appropriate call: 
    
         luabind::resume_function<void>(func, _self);
      */
    }
    

    And in Lua:

    class 'Derived' (Base)
      function Derived:__init()
        Base.__init(self, self)     -- the second self is param to BaseWrapper()
      end
    
      function Derived:foo()
        -- here is the target function
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Luabind to expose a base class from C++ to Lua from
Using luabind 0.81 Simple test to illustrate the problem: 1) class 'A' function A:__init()
I'm trying to export a simple class to Lua using LuaBind. I took the
I am using luabind as my lua to C++ wrapper. Luabind offers a method
all. I got a stranger problem by using luabind to read a array from
Say I have a lua file: --functions.lua function testadd(a, b) return a+b end How
I'm attempting to replace an existing implementation of a queue class written in Lua
I would like to pass a function as a template argument to another function
I've discovered while trying to use a luaBind-style class binding system that passing pointers
I'm using Luabind to integrate LUA into one of my projects, and the following

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.