Hello
I've been playing around with Nim a bit, and I like what I see. Now I'm trying to port my C++ Lua framework to it, but I've got a problem. The part of C++ Code I can't get to work in Nimrod is this:
luaL_Reg led[] = { {"__index", L_LED_Get}, {"__newindex", L_LED_Set}, {NULL, NULL} }; luaL_newmetatable(L, MT_LED); luaL_setfuncs(L, led, 0);
lua_setfuncs(lua_State* L, luaL_Reg* L2, nup: int);
In Nimrod, the declaration of setfuncs is this:
proc setfuncs*(L: PState; L2: ptr luaL_Reg; nup: cint) {.iluaL.}
and the code I have now is this:
let led:array[2, LuaL_Reg] = [(cstring("__index"), TCFunction(Index)),(cstring("__newindex"), TCFunction(Index))] state.SetFuncs(led, 0) #doesn't compile
So how do I transform this array in to a "C-Style" pointer array?
I may be wrong, but I think you want to take the addr of the 0th element in the array:
state.SetFuncs(led[0].addr, 0)
main.nim(20, 24) Error: expression has no address
change
"let led" to "var led":
var led:array[2, LuaL_Reg] = [(cstring("__index"), TCFunction(Index)),(cstring("__newindex"), TCFunction(Index))]
state.SetFuncs(led[0].addr, 0)
Try just changing :
state.SetFuncs(led, 0)
to:
state.SetFuncs(addr led, 0)