The error messages can be a pain and really unhelpful sometimes

Here are some genuine working code snippets.
luup.variable_watch("device_power_state_change", "urn:upnp-org:serviceId:SwitchPower1","Status", 112)
sets up the callback to the function pasted below
function device_power_state_change(dev_id,service, variable, old_val, new_val)
-- called when a device is switched on or off - from a variable_watch
if new_val == "1" then
device_switched_on_or_off(dev_id,"true") -- NOTE WE ARE USING A TEXT STRING FOR TRUE NOT A BOOLEAN VALUE
else
device_switched_on_or_off(dev_id,"false")
end
end
as an aside(and you may know this already) but when I'm testing a function (such as that above) if you copy and paste it into the test luup code box and run it, it will seemingly do nothing but it does get registered, so then you can clear the text box and happily call it. If it doesn't work right then you can tweak the code in an editor and then paste the function in again and it will use the new code. Of course as soon as you restart Lua for whatever reason the function goes back to what's defined in your luup files. Doing it this way means you haven't got to save your code and upload it each time.