mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-04 05:23:34 +00:00
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) {
|
if (type == LUA_TNUMBER) {
|
||||||
size = lua_tonumber(L, 1);
|
size = lua_tonumber(L, 1);
|
||||||
data = calloc(1, size);
|
data = calloc(1, size);
|
||||||
} else {
|
} else if (type == LUA_TSTRING) {
|
||||||
const char* str = luaL_checklstring(L, 1, &size);
|
const char* str = luaL_checklstring(L, 1, &size);
|
||||||
data = malloc(size + 1);
|
data = malloc(size + 1);
|
||||||
memcpy(data, str, size);
|
memcpy(data, str, size);
|
||||||
data[size] = '\0';
|
data[size] = '\0';
|
||||||
|
} else {
|
||||||
|
Blob* blob = luax_checktypeof(L, 1, Blob);
|
||||||
|
size = blob->size;
|
||||||
|
data = malloc(size);
|
||||||
}
|
}
|
||||||
const char* name = luaL_optstring(L, 2, "");
|
const char* name = luaL_optstring(L, 2, "");
|
||||||
Blob* blob = lovrBlobCreate(data, size, name);
|
Blob* blob = lovrBlobCreate(data, size, name);
|
||||||
|
|
Loading…
Reference in a new issue