raiseEvent works with everything but tables?

Post Reply
ktiedt
Posts: 31
Joined: Wed Feb 20, 2013 1:08 am

raiseEvent works with everything but tables?

Post by ktiedt »

I was expecting to write an event handler that accepted a table, to avoid a long function declaration however...
<raiseEvent: bad argument #2 type (string, number, boolean, or nil expected, got a table!)>
I'm curious, is this an oversight or an intentional decision to not support tables?

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: raiseEvent works with everything but tables?

Post by Nyyrazzilyss »

I don't know if it was intentional or not, but it can be worked with using the function pair yajl.to_string / yajl.to_value

These function encode a table into a usable string, and decode the string back into a table.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: raiseEvent works with everything but tables?

Post by Vadi »

Yeah table serialisation can get tricky - remember even a function is a first-class citizen in Lua a valid member of a table. Go with the serialisation Nyyrazzilyss proposed if you don't want to split your data into arguments for the event.

User avatar
SlySven
Posts: 1023
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: raiseEvent works with everything but tables?

Post by SlySven »

Phew the type detection code did it's job and spotted a table - 8-) - Yeah! Wot the others said - the code to past a table through the Event code would be more complicated than I would be willing (or understand enough about :? ) to do... :geek:

Post Reply