-- playground function printf(s,...) return io.write(s:format(...)) end -- -------------------------------------------------------------------- -- SuperIO Winbond W83627 component superio_w83627thg = { superio_base = 0x2e; } function superio_w83627thg:IO_read_filter(a,b) printf("Filter: Winbond %x, %x\n", a, b); end -- -------------------------------------------------------------------- -- SuperIO SMSC something else component superio_smsc = { superio_base = 0x2e; } function superio_smsc:new(o) o = o or { } -- create object if user does not provide one setmetatable(o, self) self.__index = self return o end function superio_smsc:init(base) self.superio_base = base; end function superio_smsc:IO_read_filter(a,b) printf("Filter: SMSC %x, %x\n", a, self.superio_base); end -- -------------------------------------------------------------------- -- of course 3 superios is stupid, but it's a simple example first_superio = superio_w83627thg -- only one in the system, so no meta table hacks second_superio = superio_smsc:new{} third_superio = superio_smsc:new{superio_base=0x4e} -- third_superio:init(0x4e) -- -------------------------------------------------------------------- -- create a linked list with all components components = nil components = { next = components, component = first_superio } components = { next = components, component = second_superio } components = { next = components, component = third_superio } -- -------------------------------------------------------------------- -- a filter could look like this local current_component = components while current_component do current_component.component:IO_read_filter(23, 14) current_component = current_component.next end -- -------------------------------------------------------------------- -- sample output: -- -- Filter: SMSC 17, 4e -- Filter: SMSC 17, 2e -- Filter: Winbond 17, e --