FIXED: Lua Player hangs on startup

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
NovaCaine
Posts: 34
Joined: Tue Dec 20, 2005 3:31 pm
Location: New Zealand
Contact:

FIXED: Lua Player hangs on startup

Post by NovaCaine »

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: 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&#40;lua_State *L&#41;
&#123;
	char path&#91;256&#93;;
	getcwd&#40;path, 256&#41;;
	lua_pushstring&#40;L, path&#41;;
	
	return 1;
&#125;

static int lua_setCurrentDirectory&#40;lua_State *L&#41;
&#123;
	const char *path = luaL_checkstring&#40;L, 1&#41;;
	if&#40;!path&#41; return luaL_error&#40;L, "Argument error&#58; System.currentDirectory&#40;file&#41; takes a filename as string as argument."&#41;;

	lua_getCurrentDirectory&#40;L&#41;;
	chdir&#40;path&#41;;
	
	return 1;
&#125;

static int lua_curdir&#40;lua_State *L&#41; &#123;
	int argc = lua_gettop&#40;L&#41;;
	if&#40;argc == 0&#41; return lua_getCurrentDirectory&#40;L&#41;;
	if&#40;argc == 1&#41; return lua_setCurrentDirectory&#40;L&#41;;
	return luaL_error&#40;L, "Argument error&#58; System.currentDirectory&#40;&#91;file&#93;&#41; takes zero or one argument."&#41;;
&#125;

// Makes a new directory - code taken from lua-fs
static int lua_mkdir&#40;lua_State *L&#41; &#123;
	const char *path;

	if &#40;lua_isstring&#40;L, 1&#41;&#41;
		path = lua_tostring&#40;L, 1&#41;;
	else
		return 0;

	mkdir&#40;path, 0777&#41;;

	/* Success */
	return 1;
&#125;

static int lua_rmFile&#40;lua_State *L&#41; &#123;
	const char *path;

	if &#40;lua_isstring&#40;L, 1&#41;&#41;
		path = lua_tostring&#40;L, 1&#41;;
	else
		return 0;

	remove&#40; path &#41;;

	return 1;
&#125;

static int lua_rmDir&#40;lua_State *L&#41; &#123;
	const char *path;

	if &#40;lua_isstring&#40;L, 1&#41;&#41;
		path = lua_tostring&#40;L, 1&#41;;
	else
		return 0;

	rmdir&#40; path &#41;;

	return 1;
&#125;

// 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&#91;&#93; = &#123;
  &#123;"currentDirectory",              lua_curdir&#125;,
  &#123;"listDirectory",           	    lua_dir&#125;,
  &#123;"makeDirectory",           	    lua_mkdir&#125;,
  &#123;"removeDirectory",           	lua_rmDir&#125;,
  &#123;"removeFile",           			lua_rmFile&#125;,
  &#123;"usbDiskModeActivate",           lua_usbActivate&#125;,
  &#123;"usbDiskModeDeactivate",    	    lua_usbDeactivate&#125;,
  &#123;"powerIsPowerOnline",            lua_powerIsPowerOnline&#125;,
  &#123;"powerIsBatteryExist",           lua_powerIsBatteryExist&#125;,
  &#123;"powerIsBatteryCharging",        lua_powerIsBatteryCharging&#125;,
  &#123;"powerGetBatteryChargingStatus", lua_powerGetBatteryChargingStatus&#125;,
  &#123;"powerIsLowBattery",             lua_powerIsLowBattery&#125;,
  &#123;"powerGetBatteryLifePercent",    lua_powerGetBatteryLifePercent&#125;,
  &#123;"powerGetBatteryLifeTime",       lua_powerGetBatteryLifeTime&#125;,
  &#123;"powerGetBatteryTemp",           lua_powerGetBatteryTemp&#125;,
  &#123;"powerGetBatteryVolt",           lua_powerGetBatteryVolt&#125;,
  &#123;"md5sum",                        lua_md5sum&#125;,
  &#123;"sioInit",                       lua_sioInit&#125;,
  &#123;"sioRead",                       lua_sioRead&#125;,
  &#123;"sioWrite",                      lua_sioWrite&#125;,
  &#123;"irdaInit",                      lua_irdaInit&#125;,
  &#123;"irdaRead",                      lua_irdaRead&#125;,
  &#123;"irdaWrite",                     lua_irdaWrite&#125;,
  &#123;"sleep",                         lua_sleep&#125;,
  &#123;"getFreeMemory",                 lua_getFreeMemory&#125;,
  &#123;0, 0&#125;
&#125;;
void luaSystem_init&#40;lua_State *L&#41; &#123;
	luaL_openlib&#40;L, "System", System_functions, 0&#41;;
&#125;


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.
Post Reply