Previous Thread
Next Thread
Print Thread
#109535 - 05/07/17 11:32 PM Are Lua scripts able to emit input events?  
Joined: Jul 2011
Posts: 91
TSCHAK Offline
Member
TSCHAK  Offline
Member

Joined: Jul 2011
Posts: 91
AM ONLY ASKING BECAUSE DOCS ARE SCARCE, AND THE LUA BRIDGE CODE ISN'T CLICKING ENTIRELY IN MY HEAD, YET...

Are Lua scripts able to emit input events? or do things like change media currently in drives?

I am currently having to write a whole lot of custom code in MAME to do this programmatically over a TCP/IP interface, and I would love to know if I could do it in Lua instead, and avoid having to butcher the %(@#!# out of the main codebase?

-Thom

#109536 - 05/08/17 01:27 AM Re: Are Lua scripts able to emit input events? [Re: TSCHAK]  
Joined: Jan 2012
Posts: 671
crazyc Online content
Senior Member
crazyc  Online Content
Senior Member

Joined: Jan 2012
Posts: 671
Yes, ioport_field:set_value(value), see the example at https://gist.github.com/cracyc/02cbcac7b869329e7d8b280ef6c77fa5. Yes, machine:images[]:load(path), this is untested, let me know if it doesn't work. emu.file:open("socket.127.0.0.1:1234") can open sockets too just like the bitbanger. The overall layout of the bridge, for better or worse, is basically the same as mame overall.

#109537 - 05/08/17 07:49 AM Re: Are Lua scripts able to emit input events? [Re: TSCHAK]  
Joined: Jul 2011
Posts: 91
TSCHAK Offline
Member
TSCHAK  Offline
Member

Joined: Jul 2011
Posts: 91
Dude, I could hug you right now. Thank you.

-Thom

#109538 - 05/08/17 11:01 AM Re: Are Lua scripts able to emit input events? [Re: TSCHAK]  
Joined: Jan 2012
Posts: 671
crazyc Online content
Senior Member
crazyc  Online Content
Senior Member

Joined: Jan 2012
Posts: 671
Also, if you use -console on the command line you'll get a shell that'll let you enter Lua commands directly for testing and -autoboot_script runs a script file without having to make a full plugin.

#109540 - 05/08/17 04:03 PM Re: Are Lua scripts able to emit input events? [Re: TSCHAK]  
Joined: Jul 2011
Posts: 91
TSCHAK Offline
Member
TSCHAK  Offline
Member

Joined: Jul 2011
Posts: 91
what's the difference in making a full plugin? (This will become a very permanent part of my smart home system, so maybe that makes more sense, once it's developed)..

..also, WOW... IT IS wired into everything... I can completely jettison all that custom C++ code. I'm....amazed....

-Thom

#109542 - 05/08/17 04:41 PM Re: Are Lua scripts able to emit input events? [Re: TSCHAK]  
Joined: Jan 2012
Posts: 671
crazyc Online content
Senior Member
crazyc  Online Content
Senior Member

Joined: Jan 2012
Posts: 671
The only real difference is that plugins are run at the program start and are persistent while autoboot_scripts are run every time the emulation is reset. The MarI/O port I linked to is an autoboot_script because it is only needed while the game is running but sounds like for what you want a plugin might be more appropriate.

#109585 - 05/15/17 12:40 AM Re: Are Lua scripts able to emit input events? [Re: TSCHAK]  
Joined: Jul 2011
Posts: 91
TSCHAK Offline
Member
TSCHAK  Offline
Member

Joined: Jul 2011
Posts: 91
Am getting: [MAME]> socket = emu.file:open("socket.127.0.0.1:1234")
error: [string "socket = emu.file:open("socket.127.0.0.1:1234..."]:1: sol: received nil for 'self' argument (use ':' for accessing member functions, make sure member variables are preceeded by the actual object with '.' syntax)

-Thom

#109586 - 05/15/17 12:45 AM Re: Are Lua scripts able to emit input events? [Re: TSCHAK]  
Joined: Jan 2012
Posts: 671
crazyc Online content
Senior Member
crazyc  Online Content
Senior Member

Joined: Jan 2012
Posts: 671
You need to create the emu.file object first with emu.file(""). The string parameter would be the search path if you were opening a file but since you're creating a socket it can be empty.

Edit: That's emu.file("", 7) where 7 is OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, need to document that somewhere.

Last edited by crazyc; 05/15/17 12:50 AM.

Who's Online Now
8 registered members (crazyc, Vas Crabb, Stiletto, Dorando, Pernod, R. Belmont, Reznor007, 1 invisible), 14 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Shout Box
Forum Statistics
Forums9
Topics8,412
Posts108,941
Members4,757
Most Online225
May 26th, 2014
Powered by UBB.threads™ PHP Forum Software 7.6.0
Page Time: 0.033s Queries: 15 (0.014s) Memory: 4.9849 MB (Peak: 5.2160 MB) Zlib enabled. Server Time: 2017-09-25 14:55:17 UTC