mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Added the "ctr.news" API. WIP, should not work correctly. Seriously, don't use it. Don't even load it.
This commit is contained in:
parent
64dbc95fde
commit
4d4838d392
2 changed files with 58 additions and 2 deletions
|
|
@ -3,13 +3,15 @@
|
||||||
|
|
||||||
int load_gfx_lib(lua_State *L);
|
int load_gfx_lib(lua_State *L);
|
||||||
int load_os_lib(lua_State *L);
|
int load_os_lib(lua_State *L);
|
||||||
|
int load_news_lib(lua_State *L);
|
||||||
|
|
||||||
static const struct luaL_Reg ctr_lib[] = {
|
static const struct luaL_Reg ctr_lib[] = {
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct { char *name; int (*load)(lua_State *L); } ctr_libs[] = {
|
struct { char *name; int (*load)(lua_State *L); } ctr_libs[] = {
|
||||||
{ "gfx", load_gfx_lib },
|
{ "gfx", load_gfx_lib },
|
||||||
|
{ "news", load_news_lib },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -27,4 +29,4 @@ int luaopen_ctr_lib(lua_State *L) {
|
||||||
void load_ctr_lib(lua_State *L) {
|
void load_ctr_lib(lua_State *L) {
|
||||||
load_os_lib(L);
|
load_os_lib(L);
|
||||||
luaL_requiref(L, "ctr", luaopen_ctr_lib, 0);
|
luaL_requiref(L, "ctr", luaopen_ctr_lib, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
54
source/news.c
Normal file
54
source/news.c
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
#include <3ds/types.h>
|
||||||
|
#include <3ds/util/utf.h>
|
||||||
|
#include <3ds/services/news.h>
|
||||||
|
|
||||||
|
#include <lua.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
|
|
||||||
|
static int news_init(lua_State *L) {
|
||||||
|
newsInit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int news_notification(lua_State *L) {
|
||||||
|
const char *title = luaL_checkstring(L, 1);
|
||||||
|
const char *message = luaL_checkstring(L, 2);
|
||||||
|
const void *imageData = luaL_checkstring(L, 3);
|
||||||
|
bool jpeg = false;
|
||||||
|
if (lua_isboolean(L, 4))
|
||||||
|
jpeg = lua_toboolean(L, 4);
|
||||||
|
|
||||||
|
const u16* cTitle = 0;
|
||||||
|
const u16* cMessage = 0;
|
||||||
|
u32 titleLength, messageLength, imageDataLength = 0;
|
||||||
|
|
||||||
|
titleLength = (u32) utf8_to_utf16((uint16_t*)cTitle, (uint8_t*)title, sizeof(title));
|
||||||
|
messageLength = (u32) utf8_to_utf16((uint16_t*)cMessage, (uint8_t*)message, sizeof(message));
|
||||||
|
|
||||||
|
NEWSU_AddNotification(cTitle, titleLength, cMessage, messageLength, imageData, imageDataLength, jpeg);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int news_shutdown(lua_State *L) {
|
||||||
|
newsExit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct luaL_Reg news_lib[] = {
|
||||||
|
{"init", news_init },
|
||||||
|
{"notification", news_notification},
|
||||||
|
{"shutdown", news_shutdown },
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
int luaopen_news_lib(lua_State *L) {
|
||||||
|
luaL_newlib(L, news_lib);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_news_lib(lua_State *L) {
|
||||||
|
luaL_requiref(L, "ctr.news", luaopen_news_lib, 0);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue