IntroductionThis is going to show you how you can use DLua to register a simple function in Lua. More advanced examples will come later. Codetest.dimport dlua.all;
import std.stdio;
extern (C) int testfunction(lua_State* L)
{
writefln("Hello from D!");
return 0;
}
void main()
{
lua_State* L = luaL_newstate();
luaL_openlibs(L);
lua_register(L, "testfunction", &testfunction);
luaL_dostring(L, `testfunction()`);
lua_close(L);
}
|
Thank you for this cool bindings. But there is one mistake in this "FunctionExample".
Line "lua_register(L, "testfunction", &testfunction);"
has to be changed to
lua_register(L, "testfunction", cast(int(*)(void** L))&testfunction);
otherwise I get the following error (in Linux; Distri : Ubuntu Gutsy Gibbon Beta:
test.d:14: function test.testfunction (void) does not match parameter types () test.d:14: Error: expected 1 arguments, not 0 test.d:14: function dlua.lua.lua_register (void,char,int()(void L)) does not match parameter types (void,char12u?,int) test.d:14: Error: cannot implicitly convert expression (testfunction()) of type int to int()(void L)