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

fix(lua): io.read always reading 256 bytes rather than specified value #5833

Merged
merged 1 commit into from
Jan 25, 2025

Conversation

frankiearzu
Copy link
Contributor

@frankiearzu frankiearzu commented Jan 25, 2025

Fixes #5832

Summary of changes:
Use parameter "n" instead of the fix LUAL_BUFFERSIZE

image

@pfeerick pfeerick changed the title #5832 Fix for LUA io.read fix(lua): io.read always reading 256 bytes rather than specified value Jan 25, 2025
@pfeerick pfeerick added lua bug/regression ↩️ A new version of EdgeTX broke something labels Jan 25, 2025
@pfeerick pfeerick added this to the 2.11 milestone Jan 25, 2025
@frankiearzu
Copy link
Contributor Author

Validated in TX16S.. Forward Programming (DSMTools) works again in 2.11

@pfeerick pfeerick merged commit 377afcf into EdgeTX:main Jan 25, 2025
51 checks passed
@frankiearzu frankiearzu deleted the LUA_IOREAD branch January 25, 2025 05:46
@raphaelcoeffic
Copy link
Member

raphaelcoeffic commented Jan 25, 2025

@frankiearzu This code comes straight from Lua code. I believe the intent is actually to buffer I/O ops by reading full buffer size when possible, and then returning only what you asked. You might want to check the original Lua code to see how it is actually supposed to work. Reading a couple bytes from FatFs is very inefficient.

@raphaelcoeffic
Copy link
Member

Nevermind, the original Lua code is doing the same:

static int read_chars (lua_State *L, FILE *f, size_t n) {
  size_t nr;  /* number of chars actually read */
  char *p;
  luaL_Buffer b;
  luaL_buffinit(L, &b);
  p = luaL_prepbuffsize(&b, n);  /* prepare buffer to read whole block */
  nr = fread(p, sizeof(char), n, f);  /* try to read 'n' chars */
  luaL_addsize(&b, nr);
  luaL_pushresult(&b);  /* close buffer */
  return (nr > 0);  /* true iff read something */
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/regression ↩️ A new version of EdgeTX broke something lua
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EdgeTx 2.11: LUA io.read(file, n) always reading 256 bytes regardless of the value of "n".
3 participants