コード例 #1
0
ファイル: g_lua.cpp プロジェクト: OnlyTheGhosts/OWEngine
void G_InitLua_Local( char mapname[MAX_STRING_CHARS] )
{

	int             numdirs;
	int             numFiles;
	char            filename[128];
	char            dirlist[1024];
	char*           dirptr;
	int             i;
	int             dirlen;
	
	numFiles = 0;
	
	numdirs = g_vfs->FS_GetFileList( va( "maps/%s/", mapname ), ".lua", dirlist, 1024 );
	dirptr = dirlist;
	for ( i = 0; i < numdirs; i++, dirptr += dirlen + 1 )
	{
		dirlen = strlen( dirptr );
		strcpy( filename, va( "maps/%s/", mapname ) );
		strcat( filename, dirptr );
		numFiles++;
		
		// load the file
		G_LoadLuaScript( filename );
		
	}
	
	g_core->Print( "%i local files parsed\n", numFiles );
	
}
コード例 #2
0
ファイル: g_lua.cpp プロジェクト: OnlyTheGhosts/OWEngine
void G_InitLua_Global()
{

	int             numdirs;
	int             numFiles;
	char            filename[128];
	char            dirlist[1024];
	char*           dirptr;
	int             i;
	int             dirlen;
	
	numFiles = 0;
	
	numdirs = g_vfs->FS_GetFileList( "lua/global/", ".lua", dirlist, 1024 );
	dirptr = dirlist;
	for ( i = 0; i < numdirs; i++, dirptr += dirlen + 1 )
	{
		dirlen = strlen( dirptr );
		strcpy( filename, "lua/global/" );
		strcat( filename, dirptr );
		numFiles++;
		
		// load the file
		G_LoadLuaScript( filename );
		
	}
	
	g_core->Print( "%i global files parsed\n", numFiles );
	
}
コード例 #3
0
ファイル: g_lua.c プロジェクト: otty/cake3
/*
============
G_InitLua
============
*/
void G_InitLua()
{
	char            buf[MAX_STRING_CHARS];
	char			filename[MAX_QPATH];
	
	G_Printf("------- Lua Initialization -------\n");

	g_luaState = lua_open();

	// Lua standard lib
	luaopen_base(g_luaState);
	luaopen_string(g_luaState);

	// Quake lib
	luaopen_entity(g_luaState);
	luaopen_game(g_luaState);
	luaopen_qmath(g_luaState);
	luaopen_vector(g_luaState);
	
	// load map specific Lua script as default
	trap_Cvar_VariableStringBuffer("mapname", buf, sizeof(buf));
	Com_sprintf(filename, sizeof(filename), "scripts/lua/%s.lua", buf);
	
	G_LoadLuaScript(NULL, filename);

	G_Printf("-----------------------------------\n");
}
コード例 #4
0
ファイル: g_lua.cpp プロジェクト: OnlyTheGhosts/OWEngine
/*
============
G_InitLua
============
*/
void G_InitLua()
{
	char            buf[MAX_STRING_CHARS];
	
	G_Printf( "------- Game Lua Initialization -------\n" );
	
	g_luaState = lua_open();
	
	// Lua standard lib
	luaopen_base( g_luaState );
	luaopen_string( g_luaState );
	
	// Quake lib
	luaopen_entity( g_luaState );
	luaopen_game( g_luaState );
	luaopen_qmath( g_luaState );
	luaopen_vector( g_luaState );
	
	// Create the callback table (at location 1 in the registry)
	lua_pushnumber( g_luaState, 1 );
	lua_newtable( g_luaState );
	lua_settable( g_luaState, LUA_REGISTRYINDEX );
	
	// load global scripts
	G_Printf( "global lua scripts:\n" );
	G_InitLua_Global();
	
	// load map-specific lua scripts
	G_Printf( "map specific lua scripts:\n" );
	g_cvars->Cvar_VariableStringBuffer( "mapname", buf, sizeof( buf ) );
	G_InitLua_Local( buf );
	G_LoadLuaScript( va( "maps/%s.lua", buf ) );
	
	G_Printf( "-----------------------------------\n" );
	
	G_RunLuaFunction( g_luaState, "G_InitGame", "" );
	
}