Yes! I was doing that to load MagicaVoxel data in this project from custom resources.
I can’t remember the reason, but later I changed the code to use resource.load()
to load all data as Buffer from resources…
#define CHECK_BUF_OK(_call) \
{ \
dmBuffer::Result r = _call; \
if (r != dmBuffer::RESULT_OK) \
{ \
dmLogError("Can't create buffer or get stream: %d, line %d", r, __LINE__); \
DbgBreak(); \
} \
}
const unsigned char* LoadResourceAsBuffer(lua_State* L, const char* res_name, unsigned int* buf_size)
{
lua_getfield(L, LUA_ENVIRONINDEX, "resource");
lua_pushliteral(L, "load");
lua_gettable(L, -2);
lua_remove(L, -2);
lua_pushstring(L, res_name);
lua_call(L, 1, 1);
dmScript::LuaHBuffer* buffer = dmScript::CheckBuffer(L, -1);
dmBuffer::HBuffer hbuffer = UnpackLuaBuffer(buffer);
lua_pop(L, 1);
unsigned char* buf_data = 0;
CHECK_BUF_OK(dmBuffer::GetStream(hbuffer, dmHashString64("data"), (void**)&buf_data, buf_size, NULL, NULL));
return buf_data;
}