forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FIXED: Lua Player hangs on startup

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
NovaCaine



Joined: 20 Dec 2005
Posts: 34
Location: New Zealand

PostPosted: Mon Jan 09, 2006 6:48 am    Post subject: FIXED: Lua Player hangs on startup Reply with quote

Hey all,

I'm currently trying to add some new functions to Lua Player 0.13 (other versions not working - but I havn't tried the new EBOOT loader yet). I needed some new functionality that Lua Player didn't support so I decided to add it.

I have creating directories working fine, but when I add code to remove files and directories it hangs on startup from EBOOT loader 0.85

Any ideas what may cause this? I kinda new to the whole PSP dev thing, Have very little idea what I can/can't do. Here is the code Im trying to compile (it's only in the luasystem.cpp file)

Code:

#include <stdlib.h>
#include <pspkernel.h>

#include <pspusb.h>
#include <pspusbstor.h>
#include <psppower.h>
#include <pspdebug.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include "luaplayer.h"
#include "sio.h"

static int usbActivated = 0;
static SceUID sio_fd = -1;
static const char* sioNotInitialized = "SIO not initialized.";

SceUID irda_fd = -1;

static int lua_getCurrentDirectory(lua_State *L)
{
   char path[256];
   getcwd(path, 256);
   lua_pushstring(L, path);
   
   return 1;
}

static int lua_setCurrentDirectory(lua_State *L)
{
   const char *path = luaL_checkstring(L, 1);
   if(!path) return luaL_error(L, "Argument error: System.currentDirectory(file) takes a filename as string as argument.");

   lua_getCurrentDirectory(L);
   chdir(path);
   
   return 1;
}

static int lua_curdir(lua_State *L) {
   int argc = lua_gettop(L);
   if(argc == 0) return lua_getCurrentDirectory(L);
   if(argc == 1) return lua_setCurrentDirectory(L);
   return luaL_error(L, "Argument error: System.currentDirectory([file]) takes zero or one argument.");
}

// Makes a new directory - code taken from lua-fs
static int lua_mkdir(lua_State *L) {
   const char *path;

   if (lua_isstring(L, 1))
      path = lua_tostring(L, 1);
   else
      return 0;

   mkdir(path, 0777);

   /* Success */
   return 1;
}

static int lua_rmFile(lua_State *L) {
   const char *path;

   if (lua_isstring(L, 1))
      path = lua_tostring(L, 1);
   else
      return 0;

   remove( path );

   return 1;
}

static int lua_rmDir(lua_State *L) {
   const char *path;

   if (lua_isstring(L, 1))
      path = lua_tostring(L, 1);
   else
      return 0;

   rmdir( path );

   return 1;
}

// Move g_dir to the stack and MEET CERTAIN DOOM! If the SceIoDirent is found on the STACK instead of among the globals, the PSP WILL CRASH IN A VERY WEIRD WAY. You have been WARNED.
SceIoDirent g_dir;

.... Everything else the same until ....

static const luaL_reg System_functions[] = {
  {"currentDirectory",              lua_curdir},
  {"listDirectory",                  lua_dir},
  {"makeDirectory",                  lua_mkdir},
  {"removeDirectory",              lua_rmDir},
  {"removeFile",                    lua_rmFile},
  {"usbDiskModeActivate",           lua_usbActivate},
  {"usbDiskModeDeactivate",           lua_usbDeactivate},
  {"powerIsPowerOnline",            lua_powerIsPowerOnline},
  {"powerIsBatteryExist",           lua_powerIsBatteryExist},
  {"powerIsBatteryCharging",        lua_powerIsBatteryCharging},
  {"powerGetBatteryChargingStatus", lua_powerGetBatteryChargingStatus},
  {"powerIsLowBattery",             lua_powerIsLowBattery},
  {"powerGetBatteryLifePercent",    lua_powerGetBatteryLifePercent},
  {"powerGetBatteryLifeTime",       lua_powerGetBatteryLifeTime},
  {"powerGetBatteryTemp",           lua_powerGetBatteryTemp},
  {"powerGetBatteryVolt",           lua_powerGetBatteryVolt},
  {"md5sum",                        lua_md5sum},
  {"sioInit",                       lua_sioInit},
  {"sioRead",                       lua_sioRead},
  {"sioWrite",                      lua_sioWrite},
  {"irdaInit",                      lua_irdaInit},
  {"irdaRead",                      lua_irdaRead},
  {"irdaWrite",                     lua_irdaWrite},
  {"sleep",                         lua_sleep},
  {"getFreeMemory",                 lua_getFreeMemory},
  {0, 0}
};
void luaSystem_init(lua_State *L) {
   luaL_openlib(L, "System", System_functions, 0);
}




BTW I'm running on v2.0 firmware.

Thanks in advance.

UPDATE: Got it working now, and with the new EBOOT loader as well. Not too sure what fixed it, but I did re-apply my wallpaper again..

Anyway, these function seem to work well in Lua - I'm currently developing a Track Manager for the game Gripshift that will allow users to share tracks over the net without using a PC. If anyone is interested in the progress I'm currently posting on their forums here.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group