Hi all,

I am trying to get some lua scripting going for a layout, and I can't get it to do anything.

Sticking a print("hello") statement doesn't even seem to work.


=====================

Ok, I think I've found the problem, for some reason I don't have the layout plugin activated.

With -plugin layout on the command line, I get some layout action. Yes!


But I can't print anything? And manager isn't available...


Let's look at init.lua in plugins/layout:

It redefines machine to be manager:machine()

so normal lua code that uses manager:machine() to access machine, just becomes machine.


Code
function layout.startplugin()
        local scripts = {}
        local function prepare_layout(script)
                local env = { machine = manager:machine(), pairs = pairs, ipairs = ipairs, emu = emu, print = print,
                                  table = { insert = table.insert, remove = table.remove } }


I added a few things, like emu and print, so now I can do this, a drive led that shows activity:
Code
<script>
  local layout = {}
  local function bool10(a) if a then return 1 else return 0 end end
  function layout.frame()
     --print("oh yeah")   -- it will print oh yeah for every frame if you uncomment it
     machine:outputs():set_value("drive1led",
     bool10(emu.item(machine.devices[":sl6:diskiing:wozfdc"].items["0/active"]):read(0)==1) &amp; 
     bool10(emu.item(machine.devices[":sl6:diskiing:wozfdc"].items["0/external_io_select"]):read(0) == 0))

     machine:outputs():set_value("drive2led",bool10(emu.item(machine.devices[":sl6:diskiing:wozfdc"].items["0/active"]):read(0)==1) &amp; 
     bool10 (emu.item(machine.devices[":sl6:diskiing:wozfdc"].items["0/external_io_select"]):read(0) == 1))
  end
  return layout,"apple2"
</script>

and also in my layout I've got:


Code
       <element name="driveled">
			<disk state="1">
			<bounds x="0.07" y="0.07" width="0.86" height="0.86" />
			<color red="1.0" green="0.0" blue="0.0" alpha="1.0" />
		</disk>
		<disk state="0">
			<bounds x="0.07" y="0.07" width="0.86" height="0.86" />
			<color red="0.0" green="0.0" blue="0.0" alpha="1.0"/>
		</disk>
	</element>


	<view name="Apple2Layout">
		   <bounds x="0" y="0" width="5800" height="4800"/>
		   <screen index="0">
			<bounds x="0" y="500" width="5600" height="3840" />
		</screen> 
		<cpanel element="driveled" name="drive1led"><bounds y="50" x="4400" width="50" height="50"/><color alpha="0.85" /></cpanel>
		<cpanel element="driveled" name="drive2led"><bounds y="50" x="4500" width="50" height="50"/><color alpha="0.85" /></cpanel>
       </view>

So in the upper right, I've got two drive LEDs that light up when the respective disk drive is active. Now all I need to do is activate those drive sounds again. 8-)

I was doing a catalog at the time the snapshot was taken so the drive 1 light was on.

[Linked Image from i.imgur.com]

I noticed that it flickers more than the apple disk drives would normally,
using this:

Code
bool10(emu.item(machine.devices[":sl6:diskiing:wozfdc"].items["0/active"]):read(0)>0)

instead of

bool10(emu.item(machine.devices[":sl6:diskiing:wozfdc"].items["0/active"]):read(0)==1)
keeps the light on until the motor stops.

Last edited by Golden Child; 04/25/19 05:40 AM.