bindbc-lua
bindbc-lua copied to clipboard
How do I call `lua_pushcfunction` ?
I'm rather new to D so maybe I'm simply missing some fundamentals, but how do I add a C function to the stack?
My code:
import raylib;
import bindbc.lua;
extern(C) static int hello(lua_State *L) {
DrawText("Hello, LUA!", 960, 300, 28, Colors.BLACK);
return 1;
}
extern(C) void main()
{
LuaSupport ret = loadLua();
lua_State* mystate = luaL_newstate();
luaL_openlibs(mystate);
lua_pushcfunction(mystate, &hello);
}
This fails with cannot pass argument `& hello` of type `extern (C) int function(lua_State* L)` to parameter `extern (C) int function(lua_State*) nothrow f`
Just mark your function as nothrow (write nothrow between the function’s parameters and the {)
You won’t be able to throw exceptions from the function, but you can call functions that throw exceptions as long as you use a try-catch block that catches type Exception.
P.S. marking a module-level function static (like your hello function) doesn’t do anything.