Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary data as lua string #122

Open
fatal10110 opened this issue Sep 10, 2024 · 1 comment
Open

Binary data as lua string #122

fatal10110 opened this issue Sep 10, 2024 · 1 comment

Comments

@fatal10110
Copy link

fatal10110 commented Sep 10, 2024

I'm trying to mock Redis lua scripting behavior, and one of the challenges there is that Redis is "binary safe"
meaning u can operate with binary data (e.g images), which is stored the same was as regular strings.

As an input to lua I can get any binary(e.g utf-8 bytes, binary data)

const imageBuffer = fs.readFileSync('./1px.png') // Binray data buffer
const utfBuffer = Buffer.from('фвфв') // Utf8 string buffer

lua.glob.set("ARGV", [imageBuffer, utfBuffer])

await lua.doString(`
    print(ARGV[2] == "фвфв")
    return ARGV[1]
`)

In case of redis utf-8 passed to lua as bytes, in lua u can compare these bytes with strings
also it can return valid binary data from lua strings, in my example above, the compare will not work, but binry data will be returned properly from lua

in the other hand, If I will inject to lua the utf8 string as hex representation (with leading \x), it will successfully compare the string, but will not return valid binary data from lua script

So in general my question is, how do I pass binary data to lua?
and return binary data from there

Not sure this is wasmoon issue, but I will appreciate any help :)

Thanks

@fatal10110
Copy link
Author

fatal10110 commented Sep 13, 2024

as a workaround, I'm passing hex encoded binary data, and decode it in the lua, same for output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant