Tôi cần impelement một chức năng C cho lua script to call.I sẽ trả về một mảng như bảng từ function.I sử dụng mã blow nhưng crashed.Could bất cứ ai cho tôi biết làm thế nào để sử dụng nó?Làm thế nào để trả về mảng như bảng từ hàm C sang lua?
struct Point {
int x, y;
}
typedef Point Point;
static int returnImageProxy(lua_State *L)
{
Point points[3] = {{11, 12}, {21, 22}, {31, 32}};
lua_newtable(L);
for (int i = 0; i 3; i++) {
lua_newtable(L);
lua_pushnumber(L, points[i].x);
lua_rawseti(L, -2, 2*i+1);
lua_pushnumber(L, points[i].y);
lua_rawseti(L, -2, 2*i+2);
lua_settable(L,-3);
}
return 1; // I want to return a Lua table like :{{11, 12}, {21, 22}, {31, 32}}
}
+1, bắt tốt. – lhf