lovr.data.newBlob accepts Blobs to clone them;

This commit is contained in:
bjorn 2018-03-10 21:37:05 -08:00
parent 6916137dc6
commit 86ce6bc44a
1 changed files with 5 additions and 1 deletions

View File

@ -24,11 +24,15 @@ int l_lovrDataNewBlob(lua_State* L) {
if (type == LUA_TNUMBER) {
size = lua_tonumber(L, 1);
data = calloc(1, size);
} else {
} else if (type == LUA_TSTRING) {
const char* str = luaL_checklstring(L, 1, &size);
data = malloc(size + 1);
memcpy(data, str, size);
data[size] = '\0';
} else {
Blob* blob = luax_checktypeof(L, 1, Blob);
size = blob->size;
data = malloc(size);
}
const char* name = luaL_optstring(L, 2, "");
Blob* blob = lovrBlobCreate(data, size, name);