This will allow us to also use the same logic for lua threads and processes, later.
reorganize so that initialization is done in lua