mirror of https://github.com/bjornbytes/lovr.git
lovr.data.newBlob accepts Blobs to clone them;
This commit is contained in:
parent
6916137dc6
commit
86ce6bc44a
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue