static int l_get2dMap(lua_State *L)
{
// Get the table insert function
lua_getglobal(L, "table");
lua_getfield(L, -1, "insert");
int table_insert = lua_gettop(L);
LuaPerlinNoiseMap *o = checkobject(L, 1);
v2f p = read_v2f(L, 2);
Noise &n = o->noise;
n.perlinMap2D(p.X, p.Y);
int i = 0;
for (int y = 0; y != n.sy; y++) {
lua_pushvalue(L, table_insert);
lua_pushvalue(L, table);
for (int x = 0; x != n.xy; x++) {
lua_pushvalue(L, table_insert);
lua_pushvalue(L, table);
lua_pushnumber(L, n.result[i++]);
}
}
return 1;
}
CiAgICBzdGF0aWMgaW50IGxfZ2V0MmRNYXAobHVhX1N0YXRlICpMKQoJewoJCS8vIEdldCB0aGUgdGFibGUgaW5zZXJ0IGZ1bmN0aW9uCgkJbHVhX2dldGdsb2JhbChMLCAidGFibGUiKTsKCQlsdWFfZ2V0ZmllbGQoTCwgLTEsICJpbnNlcnQiKTsKCQlpbnQgdGFibGVfaW5zZXJ0ID0gbHVhX2dldHRvcChMKTsKCQkKCQlMdWFQZXJsaW5Ob2lzZU1hcCAqbyA9IGNoZWNrb2JqZWN0KEwsIDEpOwoJCXYyZiBwID0gcmVhZF92MmYoTCwgMik7CgkJCgkJTm9pc2UgJm4gPSBvLT5ub2lzZTsKCQluLnBlcmxpbk1hcDJEKHAuWCwgcC5ZKTsKCQlpbnQgaSA9IDA7CgkJZm9yIChpbnQgeSA9IDA7IHkgIT0gbi5zeTsgeSsrKSB7CgkJCWx1YV9wdXNodmFsdWUoTCwgdGFibGVfaW5zZXJ0KTsKCQkJbHVhX3B1c2h2YWx1ZShMLCB0YWJsZSk7CgkJCWZvciAoaW50IHggPSAwOyB4ICE9IG4ueHk7IHgrKykgewoJCQkJbHVhX3B1c2h2YWx1ZShMLCB0YWJsZV9pbnNlcnQpOwoJCQkJbHVhX3B1c2h2YWx1ZShMLCB0YWJsZSk7CgkJCQlsdWFfcHVzaG51bWJlcihMLCBuLnJlc3VsdFtpKytdKTsKCQkJfQoJCX0KCQlyZXR1cm4gMTsKCX0K