コード例 #1
0
char path_getseparator(const char* type)
{
	if (type == NULL)
		type = os_get();

	if (matches(type, "windows"))
		return '\\';
	else
		return '/';
}
コード例 #2
0
ファイル: script.c プロジェクト: BackupTheBerlios/premake-svn
int script_init()
{
	/* Create a script environment and install the standard libraries */
	L = lua_open();
	luaopen_base(L);
	luaopen_table(L);
	luaopen_io(L);
	luaopen_string(L);
	luaopen_math(L);
	luaopen_loadlib(L);

	lua_atpanic(L, panic);

	/* Register my extensions to the Lua environment */
	lua_register(L, "addoption",  addoption);
	lua_register(L, "_ALERT",     alert);
	lua_register(L, "copyfile",   copyfile);
	lua_register(L, "docommand",  docommand);
	lua_register(L, "dopackage",  dopackage);
	lua_register(L, "findlib",    findlib);
	lua_register(L, "matchfiles", matchfiles);
	lua_register(L, "newpackage", newpackage);

	/* Add some extensions to the built-in "os" table */
	lua_getglobal(L, "os");

	lua_pushstring(L, "chdir");
	lua_pushcfunction(L, chdir_lua);
	lua_settable(L, -3);

	lua_pushstring(L, "copyfile");
	lua_pushcfunction(L, copyfile);
	lua_settable(L, -3);

	lua_pushstring(L, "findlib");
	lua_pushcfunction(L, findlib);
	lua_settable(L, -3);

	lua_pushstring(L, "getcwd");
	lua_pushcfunction(L, getcwd_lua);
	lua_settable(L, -3);

	lua_pushstring(L, "rmdir");
	lua_pushcfunction(L, rmdir_lua);
	lua_settable(L, -3);

	lua_pop(L, 1);

	/* Register some commonly used Lua4 functions */
	lua_register(L, "rmdir", rmdir_lua);

	lua_getglobal(L, "table");
	lua_pushstring(L, "insert");
	lua_gettable(L, -2);
	lua_setglobal(L, "tinsert");
	lua_pop(L, 1);

	lua_getglobal(L, "os");
	lua_pushstring(L, "remove");
	lua_gettable(L, -2);
	lua_setglobal(L, "remove");
	lua_pop(L, 1);

	/* Set the global OS identifiers */
	lua_pushstring(L, os_get());
	lua_setglobal(L, "OS");

	lua_pushnumber(L, 1);
	lua_setglobal(L, os_get());

	/* Create a list of option descriptions for addoption() */
	lua_getregistry(L);
	lua_pushstring(L, "options");
	lua_newtable(L);
	lua_settable(L, -3);
	lua_pop(L, 1);

	/* Create and populate a global "options" table */
	buildOptionsTable();

	/* Create an empty list of packages */
	lua_getregistry(L);
	lua_pushstring(L, "packages");
	lua_newtable(L);
	lua_settable(L, -3);
	lua_pop(L, 1);

	/* Create a default project object */
	buildNewProject();

	/* Set hook to intercept creation of globals, used to create packages */
	lua_pushvalue(L, LUA_GLOBALSINDEX);
	lua_newtable(L);
	lua_pushstring(L, "__index");
	lua_pushcfunction(L, getglobal);
	lua_settable(L, -3);
	lua_setmetatable(L, -2);
	lua_pop(L, 1);

	return 1;
}