-
Notifications
You must be signed in to change notification settings - Fork 375
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
new library for communicating with other programs via Lua #1080
Conversation
Fantastic job!!! Thanks a lot! Probably netplay will ever become possible with all these functions. Why do the socket functions start from a capital letter though? What do you think of making them, for example, |
@vadosnaprimer : the Lua functions now all have the same camelCase names. |
Netplay is VERY complicated, it has so much to be done to make everything perfect, no emulator has perfect netplay so far. Here's the detailed break down, to give you some insight: EDIT: Sorry, wrong button. |
@Ashafix can you resolve the conflict? I tried, but github's tool for this doesn't seem to save the file. |
I'm working on it |
This is great. I'm going to merge it, but here's my feedback
|
Thanks @zeromus for resolving the conflicts! I'll start working on the suggested changes when I find some time. 1 and 2 should be probably doable but 3 would require some more input from other developers because it will surely break some other workflows. |
@Ashafix you can simply hang at #bizhawk and discuss everything before going untrusted directions. |
Well, nobody's using this feature yet but you, so it won't break anyone's workflow but yours. It's up to you. But I can tell you, from my perspective, there is a high level of interest in doing AI things with bizhawk that take a bunch of horsepower. Supporting multiple compute nodes (maybe even have some kind of workload manager done in lua or c#) would probably be useful to many people, even if it was a very canned solution, and could unlock a lot of interesting things. I'm giving you commit permissions which you're free to use to iterate on your communication framework in this repository directly. Please see us on IRC at #bizhawk before tackling any other topics. |
Congrats :) |
Did you have any ideas about callbacks implementation? For example, for creating interactively tool on C#/python, that can act as event.onmemoryread/write/execute lua functions. |
Can someone explain to me how exactly i can make use of the socketServer commands? i find myself unable to get any communication to my little python websocket server... |
Good luck! |
I tried that, HTTP Unit test and MMF test all work fine (i changed the order in PyEmuHawk.py to get any output): but the socket test throws the following error:
Interestingly i didnt select NLua in options, i selected Lua+LuaInterface yet it throws NLua exceptions? When i change to NLua it throws the following: |
Hm, I managed to create a lot of error messages with this functionality but that one is new to me. |
I am Using Python 3.6, running Windows 10 and i used the latest developer build released about 2h ago. same errors when i use the latest stable build :( should i try installing Python 3.6 instead? i manage to get a socket connection when using the lua socket library but i want to use the socketServerScreenshot function EDIT: i also tried the release where the feature was initially implemented, same results sadly... |
Did you get the same error with the other Lua socket functions or just with
the screenshot function?
Did you load any roms?
I don't think it is a Python version issue, looks more like a problem in
the Emuhawk code.
…On Sun, Feb 24, 2019, 22:05 Janu ***@***.***> wrote:
I am Using Python 3.6, running Windows 10 and i used the latest developer
build released about 2h ago. same errors when i use the latest stable build
:( should i try installing Python 3.6 instead? i manage to get a socket
connection when using the lua socket library but i want to use the
socketServerScreenshot function
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1080 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AOXv6HNNlgxPBRSVuxdlVZ4ygYwRfiBRks5vQv6VgaJpZM4RLyhZ>
.
|
When i try console.log(socketServerSend("test")) instead, it prints "Sent : -1 bytes" and the socket server is stuck at "waiting for connection". i did indeed load a rom, to be exact, "F1 World Grand Prix (U)" for the N64. i tried running the script while no rom is loaded and i get the same results |
I like the idea of communicating from Lua to other programs but is there currently a way to send data from f.e a python server to Lua?I tried the luasocket extention before to create a server on the Lua side but there seems to be a problem with the socket core dll. It would be nice to have a way to control the emulator with a python script. |
@yannickbrandt : Yes, the Lua communications module supports it. You can send data from a Lua script in Emuhawk to a Python server and receive data coming from a Python (or any other) server. e.g. in Lua the following command would take a screenshot, send it to the socket server and wait for a response:
or just to send string
The Lua scripts in this commit (e.g. https://github.com/raw/TASVideos/BizHawk/4d063f6061542921e66e8aeb23426d501fa0a7e1/Assets/Lua/UnitTests/TestCommunication_All.lua) and https://github.com/Ashafix/PyEmuHawk/blob/master/PyEmuhawk.py give some examples of how it could be done. |
@yannickbrandt : The way the PyEmuhawk is currently set-up it looks for the last byte of an image or a windows line feed Hope that helps a little bit! Try the following steps:
|
@Ashafix Yes that works, I think the check for lineendings were my problem. Thanks. |
A library which allows easier communication between Emuhawk and other programs via Lua
All new functions are written in C# and exposed in Lua.
All Lua functions have "unit tests".
A simple Python package which tests the communications features is available here:
https://github.com/Ashafix/PyEmuHawk
New Lua functions
SocketServerScreenShot()
sends a screenshot to the Socket server
SocketServerScreenShotResponse()
sends a screenshot to the Socket server and retrieves the response
SocketServerSend(message)
sends a string [message] to the Socket server
SocketServerResponse()
receives a message from the Socket server
SocketServerSuccessful()
returns the status of the last Socket server action
boolean response: true or false
SocketServerSetTimeout(timeout)
sets the timeout in milliseconds for receiving messages
mmfSetFilename(filename)
Sets the filename for the screenshots
mmfGetFilename()
Gets the filename for the screenshots
mmfScreenshot()
Saves screenshot to memory mapped file
mmfWrite(filename, message)
Writes a string [message] to a memory mapped file [filename]
mmfRead(filename, expectedLength)
Reads a string from a memory mapped file [filename]. The expected length needs to be provided to deliver accurate reads.
httpTest()
tests HTTP connections
httpTestGet()
tests the default HTTP GET connection
httpGet(url)
makes a HTTP GET request, i.e. retrieves information from a URL
httpPost(url, message)
makes a HTTP POST request to the url and sends the string as {payload: message}
httpPostScreenshot()
HTTP POST requests to the default POST URL and sends the screenshot as base64 encoded string in {screenshot: base64_encoded_string}
httpSetTimeout(timeout)
Sets HTTP timeout in milliseconds
httpSetPostUrl(url)
Sets HTTP POST URL
httpSetGetUrl(url)
Sets HTTP GET URL
httpGetPostUrl()
Gets HTTP POST URL
httpGetGetUrl()
Gets HTTP GET URL
Changes
ArgParser.cs
new options introduced
--socket_port
Sets the default socket port
--socket_ip
Sets the default socket IP
--mmf
Sets the default memory mapped filename
--url_get
Sets the default URL for GET requests
--url_post
Sets the default URL for POST requests
New dependencies
System.Net.Http
New modules
exposes most the functions in Communication.cs as via comm.FunctionName() in Lua
Testing
http://pdroms.de/files/supernintendoentertainmentsystem/airwolf-25-08-1996
emuhawk.exe --lua=TestCommunication_All.lua
Using Python:
Start PyEmuhawk.py (https://github.com/Ashafix/PyEmuHawk) with Python3
Run EmuHawk.exe from the command line
Change the IP address to your localhost IP address
emuhawk.exe --lua=BizHawk\Assets\Lua\UnitTests\TestCommunication_All.lua --socket_ip=192.168.178.39 --socket_port=9999 --url_post=http://192.168.178.39:9876/posts --url_get=http://192.168.178.39:9876/get YourROM.sfc
Expected output: