Exemplo n.º 1
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;
}
Exemplo n.º 2
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");
}