bindbc-lua :: Return tables from D
russhy
russhy at gmail.com
Sat Sep 25 21:21:29 UTC 2021
bindbc-lua expect the function to be nothrow
This should work:
```D
import std.stdio : writeln;
import std.conv : to;
import bindbc.lua;
void main()
{
lua_State* L = luaL_newstate();
luaL_openlibs(L);
lua_register(L, "funcD", &test);
string str = "x = funcD()";
luaL_loadbuffer(L, str.ptr, str.length, "line");
int error = lua_pcall(L, 0, 0, 0);
if (error != 0)
writeln(lua_tostring(L, -1).to!string);
}
nothrow int test(lua_State* L)
{
lua_newtable(L);
lua_pushstring(L, "0");
lua_pushstring(L, "test_data");
lua_settable(L, -3);
return 1;
}
```
More information about the Digitalmars-d-learn
mailing list