Basic Lua Scripting Support - #1671
Conversation
e6c2fb6 to
df0ab90
Compare
RSDuck
left a comment
There was a problem hiding this comment.
The LuaThread is a bit dubious and probably needs some thoughts how this could be implemented better.
| luaThread = new LuaThread(); | ||
| connect(luaThread,&LuaThread::signalPrint,console,&LuaConsole::onGetText); | ||
| connect(luaThread,&LuaThread::signalClearConsole,console,&LuaConsole::onClear); | ||
| connect(buttonPausePlay,&QPushButton::clicked,luaThread,&LuaThread::luaTogglePause); |
There was a problem hiding this comment.
placement of spacing here and in a bunch of other places.
|
Still some more changes needed but majority of the refactoring is done, no more LuaThread, the Lua state is created and run by the emuThread. This should hopefully address any concerns around potential race conditions. I plan on cleaning up other issues on Sunday. |
|
I think this should be good for another review, I believe I have addressed all the major issues that have been brought up. If there is anything else that I need to change or fix please let me know. There are still more features / functions I'd like to add, but this is the kind of project that could easily lead to feature creep, so I'm gonna cut myself off here. |
|
there's probably still some more things, but this is what I found from a glance. |
|
OK addressed those issues, still some bugs I found that I need to fix, I plan on working on that tomorrow. |
|
OK ready for another review @RSDuck when you have time. |
RSDuck
left a comment
There was a problem hiding this comment.
you need to go over all the changes and fix the spacing. Then once the merge conflicts have been solved I guess we can merge it.
|
OK went over everything, double checked to make sure the spacing was good. Fixed spelling errors in the markdown. Will probably need someone else to take a look at the merge conflicts at least for the .yml and CMakeLists files. |
|
blah something went wrong while resolving the merge conflict. |
|
hm I don't really understand how dependencies are managed on macOS, I can't find anything on how it's installed in the code. |
10c70eb to
a7575ec
Compare
|
To the person who talked about this PR on our IRC: If you are reading this, we are very sorry, the ban was due to the anti spam bot bot for some reason flagging your messages. Let us know how you can communicate again with us. |
|
adding on Generic's message: I removed the ban, so you can come back to the IRC. sorry about it. |
|
Hey sorry I have been kind of a ghost for a while! It's been over a year since I started this fork, I'm not super up to date on all the changes since then. I'd like to get this project working again with the current version, since I am able to continue working on it now. |
|
there have been a ton of changes on the frontend especially with regards to multi instance within one process support. At this point it would probably smarter to not rebase/merge and instead start fresh while moving over the more independent parts like the Lua interface. |
|
Understood! I'd prefer that option honestly. Most of the work was on the Lua interpreter side of things, I tried to keep the front end stuff to a minimum while working on this since I figured I'd probably need to remake the front end entirely at some point. So I won't be loosing much. Also gives me a chance to refresh my memory on how everything works. I'll make a new fork later today, once that's up I'll add a link to the new one and close this pull request. |
Hello, sorry I just saw this. I don't really know how to use IRC, and I just saw you guys added a link to the discord so I'll probably stick to that since it's more familiar. I actually started a very rudimentary merge of this branch to main. (It definitely doesn't work, I was just using the merge conflicts to track which parts of the code base I hadn't yet looked at.) Because I've been busy IRL, I haven't touched anything in about 2 weeks, but before that I was mainly trying to get an overview of all the changes made externally to the Lua scripting module itself (i.e. what kind of integration was even necessary to begin with) as well as trying to understand the general structure of the codebase (and also what pieces got refactored, which were many).
I don't see the new fork yet on your profile, but I'll push the half-merge (and some of my notes) I've got so far to mine if you want to take a look (I was in the middle of figuring out how/where to associate a Lua scripting engine for each instance, before starting to refactor the Lua module as a class that could have multiple instances). my fork with the partial merge |
|
I'll be sure to take a look at your notes, although I think for right now my goal is simply build that can get a Although yes, one of the first things that will need to be figured out is how to handle multiple instances, since that is the biggest change from back when I first started. I should be able to work on it some today, I originally wanted to start on this like 2 weeks ago but my availability has been... to keep it simple, rather unpredictable as of recently. Hopefully I will have the time to get a good start this week, however, just so everyone is aware, my progress will likely remain somewhat scattered for now. I'll be sure to post a link to new fork here once I can get, at the bare minimum, "hello world" working on a single instance so we can have a starting point. In the meantime feel free to ask me any questions! Also thanks again to everyone for the help and patience. |
|
Hello, any update on this project ? Thanks ! |
|
Small update for those interested, (thanks to everyone who reached out about this) For those who have reached out asking if they can help in any way, I only ask for a little more time to get a minimal viable version working that is compatible with the recent updates to melonDS. Once that basic frame work is setup, I will be sure to let everyone know, and will then gladly appreciate any help! |
|
Hype! |
-Still lots todo! but I have a (mostly) working version up and running!
|
OK it appears to be an issue with the Open GL rendering that I thought I had fixed, but seems to be broken now. But at least I am able to re-create the issue on my end so I'll work on fixing that. Also yes I am aware of the seg fault issue when there is no game loaded, I will add in some safeguards for that as well. |
|
I feel I should ask here. Is this PR adding a new depend for the program on lua5.4.x? If so, is it an optional runtime-depend, is it dlopen'd at runtime and thus is non-optional, or is it just a build depend? This matters to me as I maintain the OpenBSD port for melonDS, and this will change how I package it. If this is not documented as a depend already, it should be. |
|
Seeing how rocky the pull request is I'm really hoping it doesn't get abandoned, it's a very cool thing to have. |
|
I do plan to continue working on this PR I have just been quite busy this past month. I should be able to pick things up again next week. Sorry for the lack of communication on my end. |
Prevents segfault when trying to read from NDS memory before any ROM has been loaded. Now we properly throw an error to the Lua console.
|
OK fixed the issue with the segfault, ended up being caused when the lua script try's to read from the NDS memory before any game has been loaded. Now properly throws an error to the lua console instead. After I fix the current graphical issues I plan to entirely re-write the test script to test out all of the currently implemented functions. As well as make a check list of any other potential ways a lua script might cause a crash by mistake. I'll reach out once I need people to run more test again. |
Fixes bug with lua overlays not rendering properly when using openGL rendering.
cleaned up lua scripts, as well as documentation. Fixed `DrawImage` and added `DrawImageRegion` to be same as bizhawk. Fixed missing `usememorydomain` function.
|
OK the graphical issues turned out to be a simple fix in the end, the openGL shader for the lua overlays just wasn't linking properly due to a small change in how the screens are being rendered that I did not catch until now. I rewrote the test script and cleaned up some of the documentation. @Izder456 if you could run another test on OpenBSD to confirm that everything is working properly now that would be a big help. 💛 |
Seems to work on my end. Thanks! (Also- you might wanna document the new build depend on lua 5.4 in BUILD.md)
|
|
Should be good to go for anyone to review / test at this point. Let me know if there is anything else I can fix / clean up. 😄 |
|
I have forked this repository and tried my own way of adding support for Lua scripting, if anyone is still interested, you could look up my alternative, which uses sol2 and lua 5.4, adds a "scripting" button which lets you execute scripts in-game, modules "memory" to read/write memory, "emu" to pause/unpause, save and load states, functions like get_state to get the raw pixels on screen, and as you may realize, it's not focused on TAS-making, as most scripting tools in emulators are, but more on dataset-making for AI training and such, but feel free to look it up and make it fit your needs. Still experimental though |
|
im interested in this feature whats left for this to be merged into upstream 👀 |
|
I've tested this a bit, and I see some issues:
For context, most of my tests involve running the emulator for a few frames, maybe pressing a button and releasing it later, taking a screenshot and closing the emulator. I'm not sure how feasible all of this is with the current melonDS, though. I did something like this for my own emulator a few years ago, and I had to modify a few things to get it working: https://github.com/AntonioND/giibiiadvance/blob/ccb40c3cf7d9efec538858a36d4ab69bb4d0ce5c/source/lua_handler.c#L263-L270 |
Memory.write would only write zeros, I also fixed the M64 JoyStick example script.
pull updates from head
Since we target 5.4





Here is a proposed starting point to adding Lua script support for MelonDS natively. Currently has bare minimal functionality, as I would like to have others review my work before making to many additions. This is my first project in c++ so please let me know if there are any errors, or parts that I need to re-do. The aim for this is to support accessibility features and trackers, not as a comprehensive debugging tool.