Пример #1
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");
}
Пример #2
0
/*
============
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", "" );
	
}
Пример #3
0
int EntityLibrary::open(LuaState &luaState)
{
    _luaState = &luaState;
    return luaopen_entity(static_cast<lua_State*>(*_luaState));
}
Пример #4
0
int ex_lua_init () {
    // if the core already initialized, don't init it second times.
    if ( __initialized ) {
        ex_warning ( "the lua-interpreter already initialized." );
        return 1;
    }
    ex_assert_return( __L == NULL, 1, "the lua status already opened." );

    __L = lua_open();
    luaL_openlibs(__L); // open default libs

    // OPTME { 
    // clear the package.path and package.cpath
    ex_lua_dostring ( __L, "package.path = \"\"" );
    ex_lua_dostring ( __L, "package.cpath = \"\"" );

    // NOTE: we don't need any search path. 
    // in exsdk, require("module") is deprecated all script load as module.
    // clear the package.path and package.cpath
    ex_lua_dostring ( __L, "package.path = \"./?.lua\"" );
    ex_lua_dostring ( __L, "package.cpath = \"./?.so;./?.dll\"" );
    {
        char **mounts = ex_fsys_mounts();
        char **i;
        for ( i = mounts; *i != NULL; ++i  ) {
            ex_lua_add_path( __L, *i );
            ex_lua_add_cpath( __L, *i );
        }
        ex_fsys_free_list(mounts);
    }
    // } OPTME end 

    // init graphics wraps
#if ( EX_PLATFORM != EX_IOS )
    lua_settop ( __L, 0 ); // clear the stack
    luaopen_luagl (__L);
    luaopen_luaglu (__L);
#endif

    // we create global ex table if it not exists.
    ex_lua_global_module ( __L, "ex" );

    // init ex lua
    luaopen_ex (__L);

        // ======================================================== 
        // init core wraps
        // ======================================================== 

        luaopen_angf (__L);
        luaopen_vec2f (__L);
        luaopen_mat33f (__L);
        luaopen_color3f (__L);
        luaopen_color4f (__L);

        // ======================================================== 
        // init engine wraps
        // ======================================================== 

        luaopen_yield (__L);
        luaopen_time (__L);

        // ======================================================== 
        // init engine objects 
        // ======================================================== 

        luaopen_object (__L);
            luaopen_texture (__L);
                luaopen_texture2d (__L);
            luaopen_world (__L);
            luaopen_entity (__L);
            luaopen_component (__L);
                luaopen_trans2d (__L);
                luaopen_behavior (__L);
                    luaopen_lua_behavior (__L);

    lua_settop ( __L, 0 ); // clear the stack
    __initialized = true;

    return 0;
}
Пример #5
0
LuaScript::LuaScript(Kampf* kf) {
  this->L = lua_open();

  //load all of our libraries
  // luaopen_base(this->L);
  // luaopen_table(this->L);
  // luaopen_io(this->L);
  // luaopen_string(this->L);
  // luaopen_math(this->L);

  //standard libs
  luaL_openlibs(L);

  //custom libraries extending kampf

  //kf vectors
  luaopen_vector(L);
  
  //kf quaternions
  luaopen_quaternion(L);

  //SDLAssetManager
  luaopen_SDL_AM(L);
  luaopen_SDLDrawable(L);
  luaopen_SDLText(L);

  //SDLFontManager
  luaopen_SDL_FM(L);
  luaopen_SDLFont(L);

  //Entity-related
  luaopen_entity(L);
  luaopen_entityManager(L);
  luaopen_customAttribute(L);
  luaopen_abstractComponent(L);

  //components inheriting from abstract component
  luaopen_component(L);
  luaopen_collisionComponent(L);
  luaopen_physicsComponent(L);
  luaopen_graphicsComponent(L);

  //TimeManager
  luaopen_timeManager(L);
  
  //Physics
  luaopen_physicsregistry(L);
  luaopen_luaforcegenerator(L);
  luaopen_AbstractForceGenerator(L);

  if (kf != nullptr) {
    luaopen_kampf(L, kf);
    luaopen_messenger(L, kf->getMessenger());
    luaopen_message(L);
    luaopen_rulemachine(L, kf->getRuleMachine());
    luaopen_renderwindow(L, kf->getWindowContext());
  }
  else {
      std::cout << "Kampf not initialized, some functionality will not be available" << std::endl;
  }

  //hard coding the packages path to the current directory
  this->clearPath();
  this->addPath("?.lua");
  this->addPath("./scripts/?.lua");
  this->addPath("../scripts/?.lua");
}