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: Select all
#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);
}
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.