1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Updated to the latest ctrulib, Fixed some minor bugs.

Working with citra, untested on real hardware but should be OK.
IR should now work.
Let's add some 3D drawing and sound now !
This commit is contained in:
Firew0lf 2015-12-14 23:11:45 +01:00
parent b4d025d602
commit 2e782ed9ea
15 changed files with 85 additions and 91 deletions

View file

@ -585,10 +585,6 @@ struct { char *name; int value; } cam_constants[] = {
*/
{"WHITE_BALANCE_7000K", WHITE_BALANCE_7000K},
/***
@field WHITE_BALANCE_MAX
*/
{"WHITE_BALANCE_MAX", WHITE_BALANCE_MAX },
/***
@field WHITE_BALANCE_TUNGSTEN
*/
{"WHITE_BALANCE_TUNGSTEN", WHITE_BALANCE_TUNGSTEN },

View file

@ -19,7 +19,7 @@ Initialize the CFGU module.
@function init
*/
static int cfgu_init(lua_State *L) {
initCfgu();
cfguInit();
return 0;
}
@ -29,7 +29,7 @@ Disable the CFGU module.
@function shutdown
*/
static int cfgu_shutdown(lua_State *L) {
exitCfgu();
cfguExit();
return 0;
}

View file

@ -15,9 +15,9 @@ The `fs` module.
#include <lauxlib.h>
Handle *fsuHandle;
FS_archive sdmcArchive;
FS_Archive sdmcArchive;
#ifdef ROMFS
FS_archive romfsArchive;
FS_Archive romfsArchive;
#endif
/***
@ -73,9 +73,9 @@ static int fs_list(lua_State *L) {
// Get default archive
#ifdef ROMFS
FS_archive archive = romfsArchive;
FS_Archive archive = romfsArchive;
#else
FS_archive archive = sdmcArchive;
FS_Archive archive = sdmcArchive;
#endif
// Archive path override (and skip path prefix)
if (strncmp(path, "sdmc:", 5) == 0) {
@ -88,14 +88,14 @@ static int fs_list(lua_State *L) {
#endif
}
FS_path dirPath = FS_makePath(PATH_CHAR, path);
FS_Path dirPath = fsMakePath(PATH_ASCII, path);
Handle dirHandle;
FSUSER_OpenDirectory(fsuHandle, &dirHandle, archive, dirPath);
FSUSER_OpenDirectory(&dirHandle, archive, dirPath);
u32 entriesRead = 0;
do {
FS_dirent buffer;
FS_DirectoryEntry buffer;
FSDIR_Read(dirHandle, &entriesRead, 1, &buffer);
@ -113,13 +113,13 @@ static int fs_list(lua_State *L) {
lua_setfield(L, -2, "shortName");
lua_pushstring(L, (const char *)buffer.shortExt);
lua_setfield(L, -2, "shortExt");
lua_pushboolean(L, buffer.isDirectory);
lua_pushboolean(L, buffer.attributes&FS_ATTRIBUTE_DIRECTORY);
lua_setfield(L, -2, "isDirectory");
lua_pushboolean(L, buffer.isHidden);
lua_pushboolean(L, buffer.attributes&FS_ATTRIBUTE_HIDDEN);
lua_setfield(L, -2, "isHidden");
lua_pushboolean(L, buffer.isArchive);
lua_pushboolean(L, buffer.attributes&FS_ATTRIBUTE_ARCHIVE);
lua_setfield(L, -2, "isArchive");
lua_pushboolean(L, buffer.isReadOnly);
lua_pushboolean(L, buffer.attributes&FS_ATTRIBUTE_READ_ONLY);
lua_setfield(L, -2, "isReadOnly");
lua_pushinteger(L, buffer.fileSize);
lua_setfield(L, -2, "fileSize");
@ -214,22 +214,22 @@ void load_fs_lib(lua_State *L) {
fsInit();
fsuHandle = fsGetSessionHandle();
FSUSER_Initialize(fsuHandle);
FSUSER_Initialize(*fsuHandle);
sdmcArchive = (FS_archive){ARCH_SDMC, FS_makePath(PATH_EMPTY, "")};
FSUSER_OpenArchive(fsuHandle, &sdmcArchive);
sdmcArchive = (FS_Archive){ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, "")};
FSUSER_OpenArchive(&sdmcArchive);
#ifdef ROMFS
romfsArchive = (FS_archive){ARCH_ROMFS, FS_makePath(PATH_EMPTY, "")};
FSUSER_OpenArchive(fsuHandle, &romfsArchive);
romfsArchive = (FS_Archive){ARCHIVE_ROMFS, fsMakePath(PATH_EMPTY, "")};
FSUSER_OpenArchive(&romfsArchive);
#endif
luaL_requiref(L, "ctr.fs", luaopen_fs_lib, false);
}
void unload_fs_lib(lua_State *L) {
FSUSER_CloseArchive(fsuHandle, &sdmcArchive);
FSUSER_CloseArchive(&sdmcArchive);
#ifdef ROMFS
FSUSER_CloseArchive(fsuHandle, &romfsArchive);
FSUSER_CloseArchive(&romfsArchive);
#endif
fsExit();

View file

@ -9,7 +9,7 @@ The `gfx` module.
#include <sftd.h>
#include <3ds/vram.h>
#include <3ds/services/gsp.h>
//#include <3ds/services/gsp.h>
#include <lua.h>
#include <lauxlib.h>

View file

@ -51,7 +51,7 @@ Keys states
*/
// Key list based on hid.h from the ctrulib by smealum
struct { PAD_KEY key; char *name; } hid_keys_name[] = {
struct { u32 key; char *name; } hid_keys_name[] = {
{ KEY_A , "a" },
{ KEY_B , "b" },
{ KEY_SELECT , "select" },
@ -117,7 +117,7 @@ static int hid_keys(lua_State *L) {
lua_newtable(L); // up table
for (int i = 0; hid_keys_name[i].key; i++) {
PAD_KEY key = hid_keys_name[i].key;
u32 key = hid_keys_name[i].key;
char *name = hid_keys_name[i].name;
if (kDown & key) {

View file

@ -10,8 +10,7 @@ The `ir` module.
#include <lualib.h>
#include <lauxlib.h>
u32 bufferSize = 0;
u32 *buffer;
#include <string.h>
/***
Bitrate codes list (this is not a part of the module, just a reference)
@ -38,19 +37,11 @@ Bitrate codes list (this is not a part of the module, just a reference)
Initialize the IR module.
@function init
@tparam[opt=6] number bitrate bitrate of the IR module (more informations below)
@tparam[opt=2048] number buffer size of the buffer, in bytes (max 2048)
*/
static int ir_init(lua_State *L) {
u8 bitrate = luaL_optinteger(L, 1, 6);
bufferSize = luaL_optinteger(L, 2, 2048); //default: 2Kio
if (bufferSize > 2048) {
lua_pushboolean(L, false);
lua_pushstring(L, "the buffer can't be larger than 2048 bytes.");
return 2;
}
buffer = linearAlloc(bufferSize);
Result ret = IRU_Initialize(buffer, bufferSize);
Result ret = IRU_Initialize();
if (ret) {
lua_pushboolean(L, false);
lua_pushinteger(L, ret);
@ -88,37 +79,41 @@ static int ir_send(lua_State *L) {
u8 *data = (u8*)luaL_checkstring(L, 1);
u32 wait = lua_toboolean(L, 2);
Result ret = IRU_SendData(data, sizeof(data), wait);
Result ret = IRU_StartSendTransfer(data, strlen((const char*)data));
if (wait)
IRU_WaitSendTransfer();
if (ret) {
lua_pushboolean(L, false);
lua_pushinteger(L, ret);
return 2;
}
return 0;
lua_pushboolean(L, true);
return 1;
}
/***
Receive some data from the IR module.
@function receive
@tparam[opt=buffer size] number size bytes to receive
@tparam number size bytes to receive
@tparam[opt=false] boolean wait wait until the data is received
@return string data
*/
static int ir_receive(lua_State *L) {
u32 size = luaL_optinteger(L, 1, bufferSize);
u32 size = luaL_checkinteger(L, 1);
u32 wait = lua_toboolean(L, 2);
u8 *data = 0;
u32 *transfercount = 0;
u32 transfercount = 0;
Result ret = IRU_RecvData(data, size, 0x00, transfercount, wait);
Result ret = iruRecvData(data, size, 0x00, &transfercount, wait);
if (ret) {
lua_pushboolean(L, false);
lua_pushinteger(L, ret);
return 2;
}
lua_pushstring(L, (const char *)data);
lua_pushlstring(L, (const char *)data, (size_t)transfercount);
return 1;
}

View file

@ -47,7 +47,7 @@ static int news_notification(lua_State *L) {
titleLength = (u32) utf8_to_utf16((uint16_t*)cTitle, (uint8_t*)title, strlen(title));
messageLength = (u32) utf8_to_utf16((uint16_t*)cMessage, (uint8_t*)message, strlen(message));
NEWSU_AddNotification(cTitle, titleLength, cMessage, messageLength, imageData, imageDataLength, jpeg);
NEWS_AddNotification(cTitle, titleLength, cMessage, messageLength, imageData, imageDataLength, jpeg);
return 0;
}

View file

@ -4,19 +4,18 @@ The `ptm` module.
@usage local ptm = require("ctr.ptm")
*/
#include <3ds/types.h>
#include <3ds/services/ptm.h>
#include <3ds/services/ptmu.h>
#include <3ds/services/ptmsysm.h>
#include <lua.h>
#include <lauxlib.h>
static Handle *ptmHandle;
/***
Initialize the PTM module.
@function init
*/
static int ptm_init(lua_State *L) {
ptmInit();
ptmuInit();
ptmSysmInit();
return 0;
@ -27,7 +26,7 @@ Disable the PTM module.
@function shutdown
*/
static int ptm_shutdown(lua_State *L) {
ptmExit();
ptmuExit();
ptmSysmExit();
return 0;
@ -40,7 +39,7 @@ Return the shell state.
*/
static int ptm_getShellState(lua_State *L) {
u8 out = 0;
PTMU_GetShellState(ptmHandle, &out);
PTMU_GetShellState(&out);
lua_pushinteger(L, out);
@ -54,7 +53,7 @@ Return the battery level.
*/
static int ptm_getBatteryLevel(lua_State *L) {
u8 out = 0;
PTMU_GetBatteryLevel(ptmHandle, &out);
PTMU_GetBatteryLevel(&out);
lua_pushinteger(L, out);
@ -68,7 +67,7 @@ Return whether or not the battery is charging.
*/
static int ptm_getBatteryChargeState(lua_State *L) {
u8 out = 0;
PTMU_GetBatteryChargeState(ptmHandle, &out);
PTMU_GetBatteryChargeState(&out);
lua_pushboolean(L, out);
@ -82,7 +81,7 @@ Return whether or not the pedometer is counting.
*/
static int ptm_getPedometerState(lua_State *L) {
u8 out = 0;
PTMU_GetPedometerState(ptmHandle, &out);
PTMU_GetPedometerState(&out);
lua_pushboolean(L, out);
@ -96,7 +95,7 @@ Return the total steps taken with the system.
*/
static int ptm_getTotalStepCount(lua_State *L) {
u32 steps = 0;
PTMU_GetTotalStepCount(ptmHandle, &steps);
PTMU_GetTotalStepCount(&steps);
lua_pushinteger(L, steps);

View file

@ -14,7 +14,7 @@ The `qtm` module, for headtracking. New3ds only.
#include <string.h>
typedef struct {
qtmHeadtrackingInfo *info;
QTM_HeadTrackingInfo *info;
} qtm_userdata;
static const struct luaL_Reg qtm_methods[];
@ -66,7 +66,7 @@ static int qtm_getHeadtrackingInfo(lua_State *L) {
qtm_userdata *data = lua_newuserdata(L, sizeof(*data));
luaL_getmetatable(L, "LQTM");
lua_setmetatable(L, -2);
Result ret = qtmGetHeadtrackingInfo(0, data->info);
Result ret = QTM_GetHeadTrackingInfo(0, data->info);
if (ret) {
lua_pushnil(L);
return 1;

View file

@ -25,7 +25,7 @@ The UDP part is only without connection.
typedef struct {
int socket;
struct sockaddr_in addr;
struct hostent *host; // only user for client sockets
struct hostent *host; // only used for client sockets
} socket_userdata;
/***
@ -35,7 +35,7 @@ Initialize the socket module
*/
static int socket_init(lua_State *L) {
u32 size = luaL_optinteger(L, 1, 0x100000);
Result ret = SOC_Initialize((u32*)memalign(0x1000, size), size);
Result ret = socInit((u32*)memalign(0x1000, size), size);
if (ret) {
lua_pushboolean(L, false);
@ -52,7 +52,7 @@ Disable the socket module. Must be called before exiting ctrµLua.
@function shutdown
*/
static int socket_shutdown(lua_State *L) {
SOC_Shutdown();
socExit();
return 0;
}