The CAN ID is passed as the "data" parameter to the subdissector from the CAN dissector. The C code of a subdissector to handle it would be as follows:
struct can_identifier
{
guint32 id;
};
static int subdissector_function(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
{
struct can_identifier can_id;
can_id = *((struct can_identifier*)data);
if (can_id.id != 42)
{
return 0;
}
...
}
I'm not as familiar with Lua to know how to setup the equivalent, but you shouldn't need to "override" the CAN dissector to get the CAN ID.