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 instruction 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 press a D2 function, should it 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);
If I can use cfunc , why? I do not need to do anything similar in C++ . I can just pass the address of the C++ function to C , and everything just works.
source share