I finally figured out how to read the apple joystick from lua.

Code
-- this is a little function to print a table

function printt(a) local i,j; for i,j in pairs(a) do print(i,j) end end


 printt(manager:machine():ioport().ports)

:X5	sol.ioport_port*: 0x55d3d11cd778
:joystick_1_y	sol.ioport_port*: 0x55d3d11cd7f8
:X3	sol.ioport_port*: 0x55d3d11d2fa8
:keyb_special	sol.ioport_port*: 0x55d3d11cd958
:joystick_buttons	sol.ioport_port*: 0x55d3d11cd9c8
:joystick_2_y	sol.ioport_port*: 0x55d3d11cda38
:X7	sol.ioport_port*: 0x55d3d11cd698
:joystick_2_x	sol.ioport_port*: 0x55d3d11cdaa8
:a2_config	sol.ioport_port*: 0x55d3d11cd5b8
:X4	sol.ioport_port*: 0x55d3d11cd7b8
:joystick_1_x	sol.ioport_port*: 0x55d3d11cd548
:X2	sol.ioport_port*: 0x55d3d52ee878
:X1	sol.ioport_port*: 0x55d3d52ee8f8
:X8	sol.ioport_port*: 0x55d3d11cd628
:X0	sol.ioport_port*: 0x55d3d11d2cd8
:X6	sol.ioport_port*: 0x55d3d11cd708

and if you look at the apple2e.cpp code, you can see that it maps right up to this:

Code
	PORT_START("joystick_buttons")
	PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1)  PORT_PLAYER(1)            PORT_CODE(KEYCODE_0_PAD)    PORT_CODE(JOYCODE_BUTTON1)
	PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON2)  PORT_PLAYER(1)            PORT_CODE(KEYCODE_ENTER_PAD)PORT_CODE(JOYCODE_BUTTON2)
	PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON1)  PORT_PLAYER(2)            PORT_CODE(JOYCODE_BUTTON1)

so to read the buttons you can do:

Code
print(manager:machine():ioport().ports[":joystick_buttons"]:read())
0
and to test it in an if statement:

Code
if (manager:machine():ioport().ports[":joystick_buttons"]:read() & 0x10) ~= 0 then
  -- button 1 pressed
end
if (manager:machine():ioport().ports[":joystick_buttons"]:read() & 0x20) ~= 0 then
  -- button 2 pressed
end


The joystick axes come in under the names "joystick_1_x" and "joystick_1_y"

Looking at apple2e.cpp we have:
Code
static INPUT_PORTS_START( apple2_joystick )
	PORT_START("joystick_1_x")      /* Joystick 1 X Axis */
	PORT_BIT( 0xff, 0x80, IPT_AD_STICK_X) PORT_NAME("P1 Joystick X")
	PORT_SENSITIVITY(JOYSTICK_SENSITIVITY)
	PORT_KEYDELTA(JOYSTICK_DELTA)
	PORT_CENTERDELTA(JOYSTICK_AUTOCENTER)
	PORT_MINMAX(0,0xff) PORT_PLAYER(1)
	PORT_CODE_DEC(KEYCODE_4_PAD)    PORT_CODE_INC(KEYCODE_6_PAD)
	PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH)    PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH)

	PORT_START("joystick_1_y")      /* Joystick 1 Y Axis */
	PORT_BIT( 0xff, 0x80, IPT_AD_STICK_Y) PORT_NAME("P1 Joystick Y")
	PORT_SENSITIVITY(JOYSTICK_SENSITIVITY)
	PORT_KEYDELTA(JOYSTICK_DELTA)
	PORT_CENTERDELTA(JOYSTICK_AUTOCENTER)
	PORT_MINMAX(0,0xff) PORT_PLAYER(1)
	PORT_CODE_DEC(KEYCODE_8_PAD)    PORT_CODE_INC(KEYCODE_2_PAD)
	PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH)      PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)

and in lua we can read it with:

Code
print(manager:machine():ioport().ports[":joystick_1_x"]:read())
128
print(manager:machine():ioport().ports[":joystick_1_y"]:read())
128

Note that to get the input events for the joystick movement and buttons, the apple2e window must be selected.

So if you do a print(manager:machine():ioport().ports[":joystick_buttons"]:read()) from the lua console you will get zero unless you select the apple2e window, hold the joystick button(s), click on the lua console window and then do your print statement.

What's kind of interesting is that with the focus taken away from the window, the joystick and buttons will center or release but won't move away from center.