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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:05:13+00:00 2026-05-14T03:05:13+00:00

I am writing D2 bindings for Lua. This is in one of the Lua

  • 0

I am writing D2 bindings for Lua. This is in one of the Lua header files.

typedef int (*lua_CFunction) (lua_State *L);

I assume the equivalent D2 statement would be:

extern(C) alias int function( lua_State* L ) lua_CFunction;

Lua also provides an api function:

void lua_pushcfunction( lua_State* L, string name, lua_CFunction func );

If I want to push a D2 function does it have to be extern(C) or can I just use the function?

int dfunc( lua_State* L )
{
   std.stdio.writeln("dfunc");
}

extern(C) int cfunc( lua_State* L )
{
   std.stdio.writeln("cfunc");
}

lua_State* L = lua_newstate();
lua_pushcfunction(L, "cfunc", &cfunc); //This will definitely work.
lua_pushcfunction(L, "dfunc", &dfunc); //Will this work?

If I can only use cfunc, why? I don’t need to do anything like that in C++. I can just pass the address of a C++ function to C and everything just works.

  • 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-14T03:05:13+00:00Added an answer on May 14, 2026 at 3:05 am

    Yes, the function must be declared as extern (C).

    The calling convention of functions in C and D are different, so you must tell the compiler to use the C convention with extern (C). I don’t know why you don’t have to do this in C++.

    See here for more information on interfacing with C.

    It’s also worth noting that you can use the C style for declaring function arguments.

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

Sidebar

Related Questions

I would like to add arp bindings into /proc/net/arp in C . Writing into
Writing a python program, and I came up with this error while using the
I'm writing a PyQt (Python bindings for the all-powerful Qt library) application and a
I am writing a desktop app in C# for upload large sized files on
I'm writing a Qt based (QtCore) C++ library and would like to have access
I have this control template that I am writing: <Style TargetType={x:Type controls:InfoBar}> <Setter Property=Template>
I'm writing some C# bindings for the C library controlling the pulseaudio sound server,
When writing Python code using compiled extensions (the OpenCV Python bindings, for example), PyCharm
I am writing my own engine using OpenTK (basically just OpenGL bindings for C#,
I am writing Fortran bindings for C library. What is best practice on translating

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.