Example #1
0
/**
 * @brief Loads a background script by name.
 */
int background_load( const char *name )
{
   int ret;
   lua_State *L;
   const char *err;

   /* Free if exists. */
   background_clearCurrent();

   /* Load default. */
   if (name == NULL)
      bkg_cur_L = bkg_def_L;
   /* Load new script. */
   else
      bkg_cur_L = background_create( name );

   /* Comfort. */
   L = bkg_cur_L;
   if (L == NULL)
      return -1;

   /* Run Lua. */
   ret = 0;
   lua_getglobal(L,"background");
   ret = lua_pcall(L, 0, 0, 0);
   if (ret != 0) { /* error has occured */
      err = (lua_isstring(L,-1)) ? lua_tostring(L,-1) : NULL;
      WARN("Background -> 'background' : %s",
            (err) ? err : "unknown error");
      lua_pop(L, 1);
      ret = -1;
   }
   return 0;
}
Example #2
0
/**
 * @brief Cleans up the background stuff.
 */
void background_clear (void)
{
   /* Destroy current background script. */
   background_clearCurrent();

   /* Clear the backgrounds. */
   background_clearImgArr( &bkg_image_arr_bk );
   background_clearImgArr( &bkg_image_arr_ft );
}
Example #3
0
/**
 * @brief Loads a background script by name.
 */
int background_load( const char *name )
{
   int ret, errf;
   lua_State *L;
   const char *err;

   /* Free if exists. */
   background_clearCurrent();

   /* Load default. */
   if (name == NULL)
      bkg_cur_L = bkg_def_L;
   /* Load new script. */
   else
      bkg_cur_L = background_create( name );

   /* Comfort. */
   L = bkg_cur_L;
   if (L == NULL)
      return -1;

#if DEBUGGING
   lua_pushcfunction(L, nlua_errTrace);
   errf = -2;
#else /* DEBUGGING */
   errf = 0;
#endif /* DEBUGGING */

   /* Run Lua. */
   ret = 0;
   lua_getglobal(L,"background");
   ret = lua_pcall(L, 0, 0, errf);
   if (ret != 0) { /* error has occurred */
      err = (lua_isstring(L,-1)) ? lua_tostring(L,-1) : NULL;
      WARN("Background -> 'background' : %s",
            (err) ? err : "unknown error");
      lua_pop(L, 1);
   }
#if DEBUGGING
   lua_pop(L, 1);
#endif /* DEBUGGING */
   return ret;
}