Use same logic as luaB_print in console printing function.