Avoid running out of stack space by making fewer C to lua transitions. Instead of using a metamethod to call a new C function through lua when writing complex objects we write them inside the same function. This required careful management of the lua state because we would no longer be discarding it at the end of the write_stack_object_raw function. The permanents object is now kept at the second index in the stack, where before it would transition in and out.