- [NEW] tilemap.new(x,y)

- [CHG] tilemap.new i tilemap.load alliberen la surface anterior (si hi havia) del mapa
This commit is contained in:
2025-02-19 10:40:14 +01:00
parent 5306e82897
commit 45d31579d2
3 changed files with 20 additions and 2 deletions

13
lua.cpp
View File

@@ -140,10 +140,20 @@ extern "C" {
// map
// ===============================================
static int cpp_map_new(lua_State *L) {
int w = luaL_checknumber(L, 1);
int h = luaL_checknumber(L, 2);
uint8_t s = newsurf(w, h);
uint8_t old = getmap(); if (old) freesurf(old);
setmap(s);
return 0;
}
static int cpp_map_load(lua_State *L) {
const char* str = luaL_checkstring(L, 1);
setmap(loadsurf(str));
uint8_t s = loadsurf(str);
uint8_t old = getmap(); if (old) freesurf(old);
setmap(s);
return 0;
}
@@ -833,6 +843,7 @@ void push_lua_funcs() {
lua_setglobal(L, "surface");
lua_newtable(L);
lua_pushcfunction(L,cpp_map_new); lua_setfield(L, -2, "new");
lua_pushcfunction(L,cpp_map_load); lua_setfield(L, -2, "load");
lua_pushcfunction(L,cpp_map_save); lua_setfield(L, -2, "save");
lua_pushcfunction(L,cpp_map_set); lua_setfield(L, -2, "set");