int test_astable(lua_State *L) { size_t N = 100; Array A = array_new_zeros(N, ARRAY_TYPE_DOUBLE); lunum_pusharray1(L, &A); lunum_astable(L, -1); lua_replace(L, -2); return 1; }
int luaC_array_shape(lua_State *L) // ----------------------------------------------------------------------------- // If there is no argument, return the shape as a table. If the string 'array' // is given, return it as an array. // ----------------------------------------------------------------------------- { struct Array *A = lunum_checkarray1(L, 1); lunum_pusharray2(L, A->shape, ARRAY_TYPE_INT, A->ndims); if (lua_isstring(L, 2)) { if (strcmp(lua_tostring(L, 2), "array") == 0) { return 1; } } lunum_astable(L, 2); lua_replace(L, -2); return 1; }
static int luaC_array__preserve(lua_State *L) { Array *A = lunum_checkarray1(L, 1); lua_getglobal(L, "lunum"); lua_getfield(L, -1, "array"); lunum_astable(L, 1); lua_pushinteger(L, A->dtype); lua_createtable(L, A->ndims, 0); for (int d = 0; d < A->ndims; d++) { lua_pushinteger(L, A->shape[d]); lua_seti(L, -2, d+1); } return 4; }
int luaC_array_astable(lua_State *L) { lunum_astable(L, 1); return 1; }