Add lua object references

Whenever a lua script references a core struct obj, increment a counter
in the obj struct. Core code will not free the obj, if there are any
lua references pointing to it, just makes it free-floating.
When lua script ends, the lua gc will free the free-floating objects.

Also exposes u.inventory to lua.

Breaks save and bones compat.
This commit is contained in:
Pasi Kallinen
2019-12-26 18:43:39 +02:00
parent 7ea7058c01
commit 6d8d3a9557
7 changed files with 30 additions and 4 deletions

View File

@@ -839,6 +839,11 @@ lua_State *L;
return nhl_push_anything(L, ustruct[i].type, ustruct[i].ptr);
}
if (!strcmp(tkey, "inventory")) {
nhl_push_obj(L, g.invent);
return 1;
}
nhl_error(L, "Unknown u table index");
return 0;
}