Exemplo n.º 1
0
int main (int argc, char** argv)
{
	char* path;
	char* launch_name;
	char* launch_args;
	LIMaiProgram* program;

	/* Resolve game directory. */
	path = lipth_paths_get_root ();
	if (path == NULL)
	{
		lisys_error_report ();
		return 1;
	}

	/* Parse command line arguments. */
	launch_name = "default";
	launch_args = NULL;
	if (!private_parse_arguments (argc, argv, &launch_name, &launch_args))
	{
		lisys_error_report ();
		lisys_free (path);
		return 1;
	}

	/* Start the program. */
	program = limai_program_new (path, launch_name, launch_args);
	lisys_free (launch_args);
	if (program == NULL)
	{
		lisys_error_report ();
		lisys_free (path);
		return 1;
	}

	/* Execute mods until one exits without starting a new one. */
	while (program != NULL)
	{
		/* Execute the module until the script exits. */
		if (!limai_program_execute_script (program, "main.lua"))
		{
			lisys_error_report ();
			break;
		}

		/* Check if the module started another one. */
		launch_name = program->launch_name;
		launch_args = program->launch_args;
		if (launch_name == NULL)
			break;
		program->launch_name = NULL;
		program->launch_args = NULL;
		limai_program_free (program);

		/* Unload the old module and load a new one. */
		program = limai_program_new (path, launch_name, launch_args);
		lisys_free (launch_name);
		lisys_free (launch_args);
		if (program == NULL)
		{
			lisys_error_report ();
			break;
		}
	}

	/* Free all resources. */
	limai_program_free (program);
	lisys_free (path);
	SDL_Quit ();

	return 0;
}
Exemplo n.º 2
0
LIExtThread* liext_thread_inst_new (
	LIMaiProgram* program,
	lua_State*    lua,
	const char*   file,
	const char*   code,
	const char*   args)
{
	LIExtThread* self;

	/* Allocate self. */
	self = lisys_calloc (1, sizeof (LIExtThread));
	if (self == NULL)
		return NULL;
	if (code != NULL)
	{
		self->code = lisys_string_dup (code);
		if (self->code == NULL)
		{
			lisys_free (self);
			return NULL;
		}
	}
	else if (file != NULL)
	{
		self->file = lisys_string_dup (file);
		if (self->file == NULL)
		{
			lisys_free (self);
			return NULL;
		}
	}

	/* Allocate the program. */
	self->program = limai_program_new (program->paths->root, program->paths->module_name, args);
	if (self->program == NULL)
	{
		lisys_free (self->file);
		lisys_free (self->code);
		lisys_free (self);
		return NULL;
	}
	self->program->parent = program;

	/* Allocate the host userdata. */
	self->script = liscr_data_new (program->script, lua, self, LIEXT_SCRIPT_THREAD, liext_thread_inst_free);
	if (self->script == NULL)
	{
		limai_program_free (self->program);
		lisys_free (self->file);
		lisys_free (self->code);
		lisys_free (self);
		return NULL;
	}

	/* Start the thread. */
	self->thread = lisys_thread_new (private_thread_main, self);
	if (self->thread == NULL)
		return self;

	return self;
}