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

(cpn) LUA no debug printout possible #3468

Closed
1 task done
ParkerEde opened this issue Apr 12, 2023 · 3 comments · Fixed by #3472
Closed
1 task done

(cpn) LUA no debug printout possible #3468

ParkerEde opened this issue Apr 12, 2023 · 3 comments · Fixed by #3472
Labels
bug 🪲 Something isn't working triage Bug report awaiting review / sorting

Comments

@ParkerEde
Copy link
Contributor

Is there an existing issue for this problem?

  • I have searched the existing issues

What part of EdgeTX is the focus of this bug?

Companion

Current Behavior

with the current main it is no longer possible to print debug messages in the simulator's debug window from LUA Widgets or Scripts

Expected Behavior

print ("test") should print "test" in simulator debug window from LUA scripts or LUA widgets

Steps To Reproduce

  1. start simulator
  2. load a lua widget with print command or start lua script with print command
  3. debug window shows no print out

Version

Nightly (Please give date/commit below)

Transmitter

Other (Please specify below)

Operating System (OS)

Windows

OS Version

windows 11 pro 22H2

Anything else?

current main

@ParkerEde ParkerEde added bug 🪲 Something isn't working triage Bug report awaiting review / sorting labels Apr 12, 2023
@mha1
Copy link
Contributor

mha1 commented Apr 12, 2023

I can confirm the problem on W10-64Bit and started investigating. It seems fwrite() to stdout is no longer working. Using TRACE_DEBUG_WP() LUA print works:

radio\src\thirdparty\Lua\src\luaconf.h changing lines 224-234 to this will bring back LUA print to Simulator Debug console:

//#if defined(LUA_LIB) || defined(lua_c)
//#include <stdio.h>
//#define luai_writestring(s,l)	fwrite((s), sizeof(char), (l), stdout)
//#define luai_writeline()	(luai_writestring("\n", 1), fflush(stdout))
//#define luai_writestringerror(s,p) \
//        (fprintf(stderr, (s), (p)), fflush(stderr))
//#else
#define luai_writestring(s,l)       TRACE_DEBUG_WP("%s", s);
#define luai_writeline()            TRACE_DEBUG_WP("\n");
#define luai_writestringerror(s,p)  TRACE_DEBUG_WP(s, p);
//#endif

Please let me know if this might be a valid fix but I'd rather understand why fwrite() to stdout stopped working. Any ideas?

@mha1
Copy link
Contributor

mha1 commented Apr 12, 2023

Well fwrite() seems to have not been used in 2.8 and earlier. #2994 added #define LUA_LIB's to some radio/src/api_*.cpp files which forces the section of code above in radio\src\thirdparty\Lua\src\luaconf.h into the #if branch and with this to use fwrite(). But it seems the defines are necessary to set up the api_*.cpp lib tables. Removing the defines in api_*.cpp is not an option.

The above code is a fix but is it ok to change this thirdparty file?

@pfeerick
Copy link
Member

pfeerick commented Apr 13, 2023

It seems to be ok to make changes there, there have been other changes and it's not submoduled code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working triage Bug report awaiting review / sorting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants