lua: pass strings with embedded zeros as byte arrays
This was a vague idea how to handle passing byte arrays from Lua to the mpv command interface in a somewhat reasonable way. The idea was cancelled, but leave the Lua part of it, since it might get useful later, and prevents passing (and silently cutting off) such byte strings. Barely tested, let's say not tested at all.
This commit is contained in:
1 parent
e27c523a10
commit
7f67c5250a
1 file changed
+14
-3
+14
-3
@@ -678,10 +678,21 @@ static void makenode(void *tmp, mpv_node *dst, lua_State *L, int t)
|
||||
dst->format = MPV_FORMAT_FLAG;
|
||||
dst->u.flag = !!lua_toboolean(L, t);
|
||||
break;
|
||||
case LUA_TSTRING:
|
||||
dst->format = MPV_FORMAT_STRING;
|
||||
dst->u.string = talloc_strdup(tmp, lua_tostring(L, t));
|
||||
case LUA_TSTRING: {
|
||||
size_t len = 0;
|
||||
char *s = (char *)lua_tolstring(L, t, &len);
|
||||
bool has_zeros = !!memchr(s, 0, len);
|
||||
if (has_zeros) {
|
||||
mpv_byte_array *ba = talloc_zero(tmp, mpv_byte_array);
|
||||
*ba = (mpv_byte_array){talloc_memdup(tmp, s, len), len};
|
||||
dst->format = MPV_FORMAT_BYTE_ARRAY;
|
||||
dst->u.ba = ba;
|
||||
} else {
|
||||
dst->format = MPV_FORMAT_STRING;
|
||||
dst->u.string = talloc_strdup(tmp, s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LUA_TTABLE: {
|
||||
// Lua uses the same type for arrays and maps, so guess the correct one.
|
||||
int format = MPV_FORMAT_NONE;
|
||||
|
||||
Reference in new issue
Block a user