コード例 #1
0
ファイル: main-program.c プロジェクト: bsmr-games/lipsofsuna
/**
 * \brief Creates a new program instance.
 *
 * \param path Root data directory.
 * \param name Module name.
 * \param args Module arguments or NULL.
 * \return New program or NULL.
 */
LIMaiProgram* limai_program_new (
	const char* path,
	const char* name,
	const char* args)
{
	LIMaiProgram* self;

	/* Allocate self. */
	self = lisys_calloc (1, sizeof (LIMaiProgram));
	if (self == NULL)
		return NULL;
	self->args = lisys_string_dup ((args != NULL)? args : "");
	if (self->args == NULL)
	{
		lisys_free (self);
		return NULL;
	}

	/* Initialize subsystems. */
	if (!private_init (self, path, name, args))
	{
		limai_program_free (self);
		return NULL;
	}

	return self;
}
コード例 #2
0
ファイル: ext-thread.c プロジェクト: bsmr-games/lipsofsuna
void liext_thread_inst_free (
	LIExtThread* self)
{
	liext_thread_inst_set_quit (self);
	if (self->thread != NULL)
		lisys_thread_free (self->thread);
	if (self->program != NULL)
		limai_program_free (self->program);
	lisys_free (self->file);
	lisys_free (self->code);
	lisys_free (self);
}
コード例 #3
0
ファイル: main.c プロジェクト: MuskofEphesus/GodHeadLips
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;
}
コード例 #4
0
ファイル: ext-thread.c プロジェクト: bsmr-games/lipsofsuna
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;
}