mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Added the ctr.apt library, tweaked ctr.news a bit, fixed a typo in cfgu.c
This commit is contained in:
parent
2e782ed9ea
commit
5c4da69997
4 changed files with 362 additions and 7 deletions
342
source/apt.c
Normal file
342
source/apt.c
Normal file
|
|
@ -0,0 +1,342 @@
|
||||||
|
/***
|
||||||
|
The `apt` module.
|
||||||
|
Used to manage the applets and application status.
|
||||||
|
@module ctr.apt
|
||||||
|
@usage local apt = require("ctr.apt")
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <3ds/types.h>
|
||||||
|
#include <3ds/services/apt.h>
|
||||||
|
|
||||||
|
#include <lua.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
|
|
||||||
|
/***
|
||||||
|
Initialize the APT module. Useless.
|
||||||
|
@function init
|
||||||
|
*/
|
||||||
|
static int apt_init(lua_State *L) {
|
||||||
|
Result ret = aptInit();
|
||||||
|
if (ret!=0) {
|
||||||
|
lua_pushboolean(L, false);
|
||||||
|
lua_pushinteger(L, ret);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
lua_pushboolean(L, true);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Shutdown the APT module. Useless, don't use it.
|
||||||
|
@function shutdown
|
||||||
|
*/
|
||||||
|
static int apt_shutdown(lua_State *L) {
|
||||||
|
aptExit();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Open an APT session. Should only work if you don't use the homebrew menu.
|
||||||
|
@function openSession
|
||||||
|
*/
|
||||||
|
static int apt_openSession(lua_State *L) {
|
||||||
|
aptOpenSession();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Close the current APT session.
|
||||||
|
@function closeSession
|
||||||
|
*/
|
||||||
|
static int apt_closeSession(lua_State *L) {
|
||||||
|
aptCloseSession();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Set the app status.
|
||||||
|
@function setStatus
|
||||||
|
*/
|
||||||
|
static int apt_setStatus(lua_State *L) {
|
||||||
|
APT_AppStatus status = luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
|
aptSetStatus(status);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Get the app status.
|
||||||
|
@function getStatus
|
||||||
|
*/
|
||||||
|
static int apt_getStatus(lua_State *L) {
|
||||||
|
APT_AppStatus status = aptGetStatus();
|
||||||
|
|
||||||
|
lua_pushinteger(L, status);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Return to the Home menu.
|
||||||
|
@function returnToMenu
|
||||||
|
*/
|
||||||
|
static int apt_returnToMenu(lua_State *L) {
|
||||||
|
aptReturnToMenu();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Get the power status.
|
||||||
|
@function getStatusPower
|
||||||
|
@treturn boolean true if the power button has been pressed
|
||||||
|
*/
|
||||||
|
static int apt_getStatusPower(lua_State *L) {
|
||||||
|
u32 status = aptGetStatusPower();
|
||||||
|
|
||||||
|
lua_pushboolean(L, status);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Set the power status.
|
||||||
|
@function setStatusPower
|
||||||
|
@tparam boolean status new power status
|
||||||
|
*/
|
||||||
|
static int apt_setStatusPower(lua_State *L) {
|
||||||
|
u32 status = lua_toboolean(L, 1);
|
||||||
|
|
||||||
|
aptSetStatusPower(status);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Signal that the application is ready for sleeping.
|
||||||
|
@function signalReadyForSleep
|
||||||
|
*/
|
||||||
|
static int apt_signalReadyForSleep(lua_State *L) {
|
||||||
|
aptSignalReadyForSleep();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
Return the Home menu AppID.
|
||||||
|
@function getMenuAppID
|
||||||
|
@treturn number the AppID
|
||||||
|
*/
|
||||||
|
static int apt_getMenuAppID(lua_State *L) {
|
||||||
|
lua_pushinteger(L, aptGetMenuAppID());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct luaL_Reg apt_lib[] = {
|
||||||
|
{"init", apt_init },
|
||||||
|
{"shutdown", apt_shutdown },
|
||||||
|
{"openSession", apt_openSession },
|
||||||
|
{"closeSession", apt_closeSession },
|
||||||
|
{"setStatus", apt_setStatus },
|
||||||
|
{"getStatus", apt_getStatus },
|
||||||
|
{"returnToMenu", apt_returnToMenu },
|
||||||
|
{"getStatusPower", apt_getStatusPower },
|
||||||
|
{"setStatusPower", apt_setStatusPower },
|
||||||
|
{"signalReadyForSleep", apt_signalReadyForSleep},
|
||||||
|
{"getMenuAppID", apt_getMenuAppID },
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct { char *name; int value; } apt_constants[] = {
|
||||||
|
/***
|
||||||
|
@field APPID_HOMEMENU
|
||||||
|
*/
|
||||||
|
{"APPID_HOMEMENU", APPID_HOMEMENU },
|
||||||
|
/***
|
||||||
|
@field APPID_CAMERA
|
||||||
|
*/
|
||||||
|
{"APPID_CAMERA", APPID_CAMERA },
|
||||||
|
/***
|
||||||
|
@field APPID_FRIENDS_LIST
|
||||||
|
*/
|
||||||
|
{"APPID_FRIENDS_LIST", APPID_FRIENDS_LIST },
|
||||||
|
/***
|
||||||
|
@field APPID_GAME_NOTES
|
||||||
|
*/
|
||||||
|
{"APPID_GAME_NOTES", APPID_GAME_NOTES },
|
||||||
|
/***
|
||||||
|
@field APPID_WEB
|
||||||
|
*/
|
||||||
|
{"APPID_WEB", APPID_WEB },
|
||||||
|
/***
|
||||||
|
@field APPID_INSTRUCTION_MANUAL
|
||||||
|
*/
|
||||||
|
{"APPID_INSTRUCTION_MANUAL", APPID_INSTRUCTION_MANUAL},
|
||||||
|
/***
|
||||||
|
@field APPID_NOTIFICATIONS
|
||||||
|
*/
|
||||||
|
{"APPID_NOTIFICATIONS", APPID_NOTIFICATIONS },
|
||||||
|
/***
|
||||||
|
@field APPID_MIIVERSE
|
||||||
|
*/
|
||||||
|
{"APPID_MIIVERSE", APPID_MIIVERSE },
|
||||||
|
/***
|
||||||
|
@field APPID_MIIVERSE_POSTING
|
||||||
|
*/
|
||||||
|
{"APPID_MIIVERSE_POSTING", APPID_MIIVERSE_POSTING },
|
||||||
|
/***
|
||||||
|
@field APPID_AMIIBO_SETTINGS
|
||||||
|
*/
|
||||||
|
{"APPID_AMIIBO_SETTINGS", APPID_AMIIBO_SETTINGS },
|
||||||
|
/***
|
||||||
|
@field APPID_APPLICATION
|
||||||
|
*/
|
||||||
|
{"APPID_APPLICATION", APPID_APPLICATION },
|
||||||
|
/***
|
||||||
|
@field APPID_ESHOP
|
||||||
|
*/
|
||||||
|
{"APPID_ESHOP", APPID_ESHOP },
|
||||||
|
/***
|
||||||
|
@field APPID_SOFTWARE_KEYBOARD
|
||||||
|
*/
|
||||||
|
{"APPID_SOFTWARE_KEYBOARD", APPID_SOFTWARE_KEYBOARD },
|
||||||
|
/***
|
||||||
|
@field APPID_APPLETED
|
||||||
|
*/
|
||||||
|
{"APPID_APPLETED", APPID_APPLETED },
|
||||||
|
/***
|
||||||
|
@field APPID_PNOTE_AP
|
||||||
|
*/
|
||||||
|
{"APPID_PNOTE_AP", APPID_PNOTE_AP },
|
||||||
|
/***
|
||||||
|
@field APPID_SNOTE_AP
|
||||||
|
*/
|
||||||
|
{"APPID_SNOTE_AP", APPID_SNOTE_AP },
|
||||||
|
/***
|
||||||
|
@field APPID_ERROR
|
||||||
|
*/
|
||||||
|
{"APPID_ERROR", APPID_ERROR },
|
||||||
|
/***
|
||||||
|
@field APPID_MINT
|
||||||
|
*/
|
||||||
|
{"APPID_MINT", APPID_MINT },
|
||||||
|
/***
|
||||||
|
@field APPID_EXTRAPAD
|
||||||
|
*/
|
||||||
|
{"APPID_EXTRAPAD", APPID_EXTRAPAD },
|
||||||
|
/***
|
||||||
|
@field APPID_MEMOLIB
|
||||||
|
*/
|
||||||
|
{"APPID_MEMOLIB", APPID_MEMOLIB },
|
||||||
|
/***
|
||||||
|
@field APP_NOTINITIALIZED
|
||||||
|
*/
|
||||||
|
{"APP_NOTINITIALIZED", APP_NOTINITIALIZED },
|
||||||
|
/***
|
||||||
|
@field APP_RUNNING
|
||||||
|
*/
|
||||||
|
{"APP_RUNNING", APP_RUNNING },
|
||||||
|
/***
|
||||||
|
@field APP_SUSPENDED
|
||||||
|
*/
|
||||||
|
{"APP_SUSPENDED", APP_SUSPENDED },
|
||||||
|
/***
|
||||||
|
@field APP_EXITING
|
||||||
|
*/
|
||||||
|
{"APP_EXITING", APP_EXITING },
|
||||||
|
/***
|
||||||
|
@field APP_SUSPENDING
|
||||||
|
*/
|
||||||
|
{"APP_SUSPENDING", APP_SUSPENDING },
|
||||||
|
/***
|
||||||
|
@field APP_SLEEPMODE
|
||||||
|
*/
|
||||||
|
{"APP_SLEEPMODE", APP_SLEEPMODE },
|
||||||
|
/***
|
||||||
|
@field APP_PREPARE_SLEEPMODE
|
||||||
|
*/
|
||||||
|
{"APP_PREPARE_SLEEPMODE", APP_PREPARE_SLEEPMODE},
|
||||||
|
/***
|
||||||
|
@field APP_APPLETSTARTED
|
||||||
|
*/
|
||||||
|
{"APP_APPLETSTARTED", APP_APPLETSTARTED },
|
||||||
|
/***
|
||||||
|
@field APP_APPLETCLOSED
|
||||||
|
*/
|
||||||
|
{"APP_APPLETCLOSED", APP_APPLETCLOSED },
|
||||||
|
/***
|
||||||
|
@field APTSIGNAL_HOMEBUTTON
|
||||||
|
*/
|
||||||
|
{"APTSIGNAL_HOMEBUTTON", APTSIGNAL_HOMEBUTTON },
|
||||||
|
/***
|
||||||
|
@field APTSIGNAL_PREPARESLEEP
|
||||||
|
*/
|
||||||
|
{"APTSIGNAL_PREPARESLEEP", APTSIGNAL_PREPARESLEEP},
|
||||||
|
/***
|
||||||
|
@field APTSIGNAL_ENTERSLEEP
|
||||||
|
*/
|
||||||
|
{"APTSIGNAL_ENTERSLEEP", APTSIGNAL_ENTERSLEEP },
|
||||||
|
/***
|
||||||
|
@field APTSIGNAL_WAKEUP
|
||||||
|
*/
|
||||||
|
{"APTSIGNAL_WAKEUP", APTSIGNAL_WAKEUP },
|
||||||
|
/***
|
||||||
|
@field APTSIGNAL_ENABLE
|
||||||
|
*/
|
||||||
|
{"APTSIGNAL_ENABLE", APTSIGNAL_ENABLE },
|
||||||
|
/***
|
||||||
|
@field APTSIGNAL_POWERBUTTON
|
||||||
|
*/
|
||||||
|
{"APTSIGNAL_POWERBUTTON", APTSIGNAL_POWERBUTTON },
|
||||||
|
/***
|
||||||
|
@field APTSIGNAL_UTILITY
|
||||||
|
*/
|
||||||
|
{"APTSIGNAL_UTILITY", APTSIGNAL_UTILITY },
|
||||||
|
/***
|
||||||
|
@field APTSIGNAL_SLEEPSYSTEM
|
||||||
|
*/
|
||||||
|
{"APTSIGNAL_SLEEPSYSTEM", APTSIGNAL_SLEEPSYSTEM },
|
||||||
|
/***
|
||||||
|
@field APTSIGNAL_ERROR
|
||||||
|
*/
|
||||||
|
{"APTSIGNAL_ERROR", APTSIGNAL_ERROR },
|
||||||
|
/***
|
||||||
|
@field APTHOOK_ONSUSPEND
|
||||||
|
*/
|
||||||
|
{"APTHOOK_ONSUSPEND", APTHOOK_ONSUSPEND},
|
||||||
|
/***
|
||||||
|
@field APTHOOK_ONRESTORE
|
||||||
|
*/
|
||||||
|
{"APTHOOK_ONRESTORE", APTHOOK_ONRESTORE},
|
||||||
|
/***
|
||||||
|
@field APTHOOK_ONSLEEP
|
||||||
|
*/
|
||||||
|
{"APTHOOK_ONSLEEP", APTHOOK_ONSLEEP },
|
||||||
|
/***
|
||||||
|
@field APTHOOK_ONWAKEUP
|
||||||
|
*/
|
||||||
|
{"APTHOOK_ONWAKEUP", APTHOOK_ONWAKEUP },
|
||||||
|
/***
|
||||||
|
@field APTHOOK_ONEXIT
|
||||||
|
*/
|
||||||
|
{"APTHOOK_ONEXIT", APTHOOK_ONEXIT },
|
||||||
|
/***
|
||||||
|
@field APTHOOK_COUNT
|
||||||
|
*/
|
||||||
|
{"APTHOOK_COUNT", APTHOOK_COUNT },
|
||||||
|
{NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
int luaopen_apt_lib(lua_State *L) {
|
||||||
|
luaL_newlib(L, apt_lib);
|
||||||
|
|
||||||
|
for (int i = 0; apt_constants[i].name; i++) {
|
||||||
|
lua_pushinteger(L, apt_constants[i].value);
|
||||||
|
lua_setfield(L, -2, apt_constants[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_apt_lib(lua_State *L) {
|
||||||
|
luaL_requiref(L, "ctr.apt", luaopen_apt_lib, false);
|
||||||
|
}
|
||||||
|
|
@ -290,7 +290,7 @@ struct { char *name; int value; } cfgu_constants[] = {
|
||||||
It is equal to `4`.
|
It is equal to `4`.
|
||||||
@field MODEL_N3DSXL
|
@field MODEL_N3DSXL
|
||||||
*/
|
*/
|
||||||
{"MOdEL_N3DSXL", 4},
|
{"MODEL_N3DSXL", 4},
|
||||||
|
|
||||||
{NULL, 0}
|
{NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
10
source/ctr.c
10
source/ctr.c
|
|
@ -91,6 +91,13 @@ The `ctr.cam` module.
|
||||||
*/
|
*/
|
||||||
void load_cam_lib(lua_State *L);
|
void load_cam_lib(lua_State *L);
|
||||||
|
|
||||||
|
/***
|
||||||
|
The `ctr.apt` module.
|
||||||
|
@table apt
|
||||||
|
@see ctr.apt
|
||||||
|
*/
|
||||||
|
void load_apt_lib(lua_State *L);
|
||||||
|
|
||||||
/***
|
/***
|
||||||
Return whether or not the program should continue.
|
Return whether or not the program should continue.
|
||||||
@function run
|
@function run
|
||||||
|
|
@ -132,7 +139,8 @@ struct { char *name; void (*load)(lua_State *L); void (*unload)(lua_State *L); }
|
||||||
{ "qtm", load_qtm_lib, NULL },
|
{ "qtm", load_qtm_lib, NULL },
|
||||||
{ "cfgu", load_cfgu_lib, NULL },
|
{ "cfgu", load_cfgu_lib, NULL },
|
||||||
{ "socket", load_socket_lib, NULL },
|
{ "socket", load_socket_lib, NULL },
|
||||||
{ "cam", load_cam_lib, NULL },
|
{ "cam", load_cam_lib, NULL },
|
||||||
|
{ "apt", load_apt_lib, NULL },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,13 @@ static int news_init(lua_State *L) {
|
||||||
Send a notification to the user. WIP, do not use !!!
|
Send a notification to the user. WIP, do not use !!!
|
||||||
@function notification
|
@function notification
|
||||||
@tparam string title title of the notification
|
@tparam string title title of the notification
|
||||||
@tparam string message message of the notification
|
@tparam[opt=nil] string message message of the notification, or nil for no message
|
||||||
@tparam string imageData data from a JPEG image (content of a file) or raw data
|
@tparam[opt=nil] string imageData data from a JPEG image (content of a file) or raw data, or nil for no image
|
||||||
@tparam[OPT=false] boolean jpeg set to `true` if the data is from a JPEG file
|
@tparam[opt=false] boolean jpeg set to `true` if the data is from a JPEG file
|
||||||
*/
|
*/
|
||||||
static int news_notification(lua_State *L) {
|
static int news_notification(lua_State *L) {
|
||||||
const char *title = luaL_checkstring(L, 1);
|
const char *title = luaL_checkstring(L, 1);
|
||||||
const char *message = luaL_checkstring(L, 2);
|
const char *message = luaL_optstring(L, 2, NULL);
|
||||||
|
|
||||||
u32 imageDataLength = 0;
|
u32 imageDataLength = 0;
|
||||||
const void *imageData = luaL_optlstring(L, 3, NULL, (size_t*)&imageDataLength);
|
const void *imageData = luaL_optlstring(L, 3, NULL, (size_t*)&imageDataLength);
|
||||||
|
|
@ -45,7 +45,12 @@ static int news_notification(lua_State *L) {
|
||||||
u32 titleLength, messageLength;
|
u32 titleLength, messageLength;
|
||||||
|
|
||||||
titleLength = (u32) utf8_to_utf16((uint16_t*)cTitle, (uint8_t*)title, strlen(title));
|
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));
|
if (message != NULL) {
|
||||||
|
messageLength = (u32) utf8_to_utf16((uint16_t*)cMessage, (uint8_t*)message, strlen(message));
|
||||||
|
} else {
|
||||||
|
messageLength = 0;
|
||||||
|
cMessage = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
NEWS_AddNotification(cTitle, titleLength, cMessage, messageLength, imageData, imageDataLength, jpeg);
|
NEWS_AddNotification(cTitle, titleLength, cMessage, messageLength, imageData, imageDataLength, jpeg);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue