Subversion Repositories pspware

Rev

Rev 349 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 349 Rev 350
Line 147... Line 147...
147
static void setModulePath()
147
static void setModulePath()
148
{
148
{
149
        getcwd( modulePath, 256 );
149
        getcwd( modulePath, 256 );
150
}
150
}
151
151
-
 
152
extern "C" {
-
 
153
        extern SceUID psploadlib( const char * name, char * init );
-
 
154
        extern void **findFunction( SceUID id, const char * library, const char * name );
-
 
155
        extern int init( lua_State *L);
-
 
156
}
-
 
157
-
 
158
#define LOADMODULE_ARGERROR "Argument error: System.loadModule(module, init) takes a module name and init method as string arguments."
-
 
159
152
static int lua_loadModule(lua_State *L)
160
static int lua_loadModule(lua_State *L)
153
{
161
{
154
        char path[256];
-
 
155
        u32 loadResult;
-
 
156
        u32 startResult;
-
 
157
        int status;
-
 
158
-
 
159
        const char *name = luaL_checkstring(L, 1);
162
        const char *name = luaL_checkstring(L, 1);
160
        if (!name) return luaL_error(L, "Argument error: System.loadModule(name) takes a module name as string as argument.");
163
        const char *init = luaL_checkstring(L, 2);
161
164
162
        strcpy( path, modulePath );
165
        SceUID uid = psploadlib( name, NULL );
163
        strcat( path, "/" );
166
        if ( uid >= 0 ) {
164
        strcat( path, name );
167
                lua_CFunction f = (lua_CFunction) *(findFunction( uid, name, init ));
165
        strcat( path, ".lrx" );
168
                if (f != NULL)
166
169
                {
167
        loadResult = sceKernelLoadModule(path,0, NULL);
170
                        lua_pushlightuserdata(L,(void*)uid);
168
        if (loadResult & 0x80000000)
171
                        lua_pushcclosure(L,f,1);
-
 
172
                        return 1;
169
        {
173
                }
170
                return luaL_error(L, "Argument error: Failed to load module");
-
 
171
        }
174
        }
172
175
173
        startResult = sceKernelStartModule( loadResult, strlen(path)+1,(void*) path, &status, NULL );
-
 
174
        if ( loadResult != startResult )
176
        lua_pushnil(L);
175
        {
-
 
176
                printf( "Module error: Failed to load module\n" );
177
        lua_pushstring(L, LOADMODULE_ARGERROR );
177
                return luaL_error(L, "Module error: Failed to load module");
178
        lua_pushstring(L, (uid >= 0) ? "init" : "open");
178
        }
-
 
179
179
180
        return 0;  
180
        return 3;
181
}
181
}
182
182
183
static int lua_usbActivate(lua_State *L)
183
static int lua_usbActivate(lua_State *L)
184
{
184
{
185
        if (lua_gettop(L) != 0) return luaL_error(L, "wrong number of arguments");
185
        if (lua_gettop(L) != 0) return luaL_error(L, "wrong number of arguments");
Line 419... Line 419...
419
  {"currentDirectory",              lua_curdir},
419
  {"currentDirectory",              lua_curdir},
420
  {"listDirectory",                 lua_dir},
420
  {"listDirectory",                 lua_dir},
421
  {"createDirectory",               lua_createDir},
421
  {"createDirectory",               lua_createDir},
422
  {"removeDirectory",               lua_removeDir},
422
  {"removeDirectory",               lua_removeDir},
423
  {"removeFile",                    lua_removeFile},
423
  {"removeFile",                    lua_removeFile},
424
  {"loadModule",                    lua_loadModule},
-
 
425
  {"usbDiskModeActivate",           lua_usbActivate},
424
  {"usbDiskModeActivate",           lua_usbActivate},
426
  {"usbDiskModeDeactivate",         lua_usbDeactivate},
425
  {"usbDiskModeDeactivate",         lua_usbDeactivate},
427
  {"powerIsPowerOnline",            lua_powerIsPowerOnline},
426
  {"powerIsPowerOnline",            lua_powerIsPowerOnline},
428
  {"powerIsBatteryExist",           lua_powerIsBatteryExist},
427
  {"powerIsBatteryExist",           lua_powerIsBatteryExist},
429
  {"powerIsBatteryCharging",        lua_powerIsBatteryCharging},
428
  {"powerIsBatteryCharging",        lua_powerIsBatteryCharging},
Line 446... Line 445...
446
  {0, 0}
445
  {0, 0}
447
};
446
};
448
void luaSystem_init(lua_State *L) {
447
void luaSystem_init(lua_State *L) {
449
        setModulePath();
448
        setModulePath();
450
        luaL_openlib(L, "System", System_functions, 0);
449
        luaL_openlib(L, "System", System_functions, 0);
-
 
450
        lua_register(L, "loadlib", lua_loadModule);
451
}
451
}
452
452