lua: Fix access to sprites in Sprites collection

This commit is contained in:
David Capello 2018-12-10 11:49:41 -03:00
parent 0203b65908
commit afa59e8aa4
2 changed files with 9 additions and 3 deletions

View File

@ -15,6 +15,8 @@ extern "C" {
#include "lauxlib.h"
}
#include "base/debug.h"
#include <functional>
#include <type_traits>
@ -61,14 +63,18 @@ template <typename T> T* get_ptr(lua_State* L, int index) {
}
template <typename T> T* get_obj(lua_State* L, int index) {
return (T*)luaL_checkudata(L, index, get_mtname<T>());
T* ptr = (T*)luaL_checkudata(L, index, get_mtname<T>());
ASSERT(typeid(*ptr) == typeid(T));
return ptr;
}
// Returns nil if the index doesn't have the given metatable
template <typename T> T* may_get_ptr(lua_State* L, int index) {
T** ptr = (T**)luaL_testudata(L, index, get_mtname<T>());
if (ptr)
if (ptr) {
ASSERT(typeid(**ptr) == typeid(T));
return *ptr;
}
else
return nullptr;
}

View File

@ -33,7 +33,7 @@ struct SpritesObj {
SpritesObj(const Docs& docs) {
for (const Doc* doc : docs)
this->docs.push_back(doc->id());
this->docs.push_back(doc->sprite()->id());
}
SpritesObj(const SpritesObj&) = delete;