Example #1
0
/**
 * @brief Initializes the CLI environment.
 */
int cli_init (void)
{
   /* Already loaded. */
   if (cli_state != NULL)
      return 0;

   /* Set the height. */
   cli_height = CLI_HEIGHT;

   /* Create the state. */
   cli_state   = nlua_newState();
   nlua_loadStandard( cli_state, 0 );
   nlua_loadCol( cli_state, 0 );
   nlua_loadTex( cli_state, 0 );
   nlua_loadBackground( cli_state, 0 );
   nlua_loadCamera( cli_state, 0 );
   nlua_loadTk( cli_state );
   nlua_loadCLI( cli_state );
   nlua_loadMusic( cli_state, 0 );
   luaL_register( cli_state, "_G", cli_methods );
   lua_settop( cli_state, 0 );

   /* Mark as console. */
   lua_pushboolean( cli_state, 1 );
   lua_setglobal( cli_state, "__cli" );

   /* Set the font. */
   cli_font    = malloc( sizeof(glFont) );
   gl_fontInit( cli_font, "dat/mono.ttf", conf.font_size_console );

   /* Clear the buffer. */
   memset( cli_buffer, 0, sizeof(cli_buffer) );

   return 0;
}
Example #2
0
/**
 * @brief Loads the graphics library.
 *
 *    @param L State to load graphics library into.
 *    @return 0 on success.
 */
int nlua_loadGFX( lua_State *L, int readonly )
{
   if (readonly) /* Nothing is read only */
      return 0;

   /* Register the values */
   luaL_register(L, "gfx", gfxL_methods);

   /* We also load the texture and colour modules as dependencies. */
   nlua_loadTex( L, readonly );
   nlua_loadCol( L, readonly );

   return 0;
}
Example #3
0
/**
 * @brief Initializes the CLI environment.
 */
int cli_init (void)
{
   /* Already loaded. */
   if (cli_state != NULL)
      return 0;

   /* Calculate size. */
   cli_width   = SCREEN_W - 100;
   cli_height  = SCREEN_H - 100;

   /* Create the state. */
   cli_state   = nlua_newState();
   nlua_loadStandard( cli_state, 0 );
   nlua_loadCol( cli_state, 0 );
   nlua_loadTex( cli_state, 0 );
   nlua_loadBackground( cli_state, 0 );
   nlua_loadCamera( cli_state, 0 );
   nlua_loadTk( cli_state );
   nlua_loadCLI( cli_state );
   nlua_loadMusic( cli_state, 0 );
   luaL_register( cli_state, "_G", cli_methods );
   lua_settop( cli_state, 0 );

   /* Mark as console. */
   lua_pushboolean( cli_state, 1 );
   lua_setglobal( cli_state, "__cli" );

   /* Set the font. */
   cli_font    = malloc( sizeof(glFont) );
   gl_fontInit( cli_font, "dat/mono.ttf", CONSOLE_FONT_SIZE );

   /* Clear the buffer. */
   memset( cli_buffer, 0, sizeof(cli_buffer) );

   /* Put a friendly message at first. */
   cli_addMessage( "Welcome to the Lua console!" );
   cli_addMessage( "" );

   return 0;
}
Example #4
0
/**
 * @brief Creates a background Lua state from a script.
 */
static lua_State* background_create( const char *name )
{
   uint32_t bufsize;
   char path[PATH_MAX];
   char *buf;
   lua_State *L;

   /* Create file name. */
   snprintf( path, sizeof(path), "dat/bkg/%s.lua", name );

   /* Create the Lua state. */
   L = nlua_newState();
   nlua_loadStandard(L,1);
   nlua_loadTex(L,0);
   nlua_loadCol(L,0);
   nlua_loadBackground(L,0);

   /* Open file. */
   buf = ndata_read( path, &bufsize );
   if (buf == NULL) {
      WARN("Default background script '%s' not found.", path);
      lua_close(L);
      return NULL;
   }

   /* Load file. */
   if (luaL_dobuffer(L, buf, bufsize, path) != 0) {
      WARN("Error loading background file: %s\n"
            "%s\n"
            "Most likely Lua file has improper syntax, please check",
            path, lua_tostring(L,-1));
      free(buf);
      lua_close(L);
      return NULL;
   }
   free(buf);

   return L;
}