8000 binary data support by fatal10110 · Pull Request #133 · ceifa/wasmoon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

binary data support #133

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

fatal10110
Copy link

This PR addresses two issues

  1. binary data can not properly be returned from lua, as it is "string" type in lua, which is assumed by wasmoon to be a regualr utf8 string

This PR handles it by reading the data directly from C memory to JS memory - Its up to you if u want to handle it this way, as it can affect performance, since it requires extra allocations

  1. Binary data can not be properly passed to lua as lua strings, that behave as lua string

This PR handles it by reading JS memory to C memory - It may be handled differentley by mocking string meta methods

src/luawasm.ts Outdated
@@ -280,6 +283,7 @@ export default class LuaWasm {
this.lua_pushnumber = this.cwrap('lua_pushnumber', null, ['number', 'number'])
this.lua_pushinteger = this.cwrap('lua_pushinteger', null, ['number', 'number'])
this.lua_pushlstring = this.cwrap('lua_pushlstring', 'string', ['number', 'string|number', 'number'])
this.lua_ptr_pushlstring = this.cwrap('lua_pushlstring', 'string', ['number', 'string|number', 'number'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type here is string, but you added the return as number on the field?

@ceifa
Copy link
Owner
ceifa commented Apr 30, 2025

Tests are failing, can you take a look?

Copy link
Owner
ceifa commented Apr 30, 2025

I guess this fixes #122?

@fatal10110
Copy link
Author
fatal10110 commented May 1, 2025

Tests are failing, can you take a look?

Looks like linter issues, will fix it, thanks

I guess this fixes #122?

Yeap, as I wrote in the description, this aproach is a bit different than what is implemented now in wasmoon, you prefer not to copy the data to C memory, and only pass a reference to it ( I guess performance reasons), but it has some limitations

The return type here is string, but you added the return as number on the field?

Right I will fix it thanks, the idea here is that it returns a pointer, not sure how it worked like that for me :D

@fatal10110
Copy link
Author

Fixed lint issues (not related to the PR, for some reason it failed)
Made the code backward compatible, string now is a type extension
Removed non used lua function definition

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

Successfully merging this pull request may close these issues.

2 participants
0