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

Added some sleep mode related functions, fixed the example, fixed some things

This commit is contained in:
Firew0lf 2016-05-09 23:28:41 +02:00
parent b4ceb200ea
commit 5494f3d2e5
5 changed files with 34 additions and 4 deletions

View file

@ -10,6 +10,7 @@ local angle = 0
local texture1 = gfx.texture.load(ctr.root.."icon.png"); local texture1 = gfx.texture.load(ctr.root.."icon.png");
if not texture1 then error("Giants ducks came from another planet") end if not texture1 then error("Giants ducks came from another planet") end
local tWidth, tHeight = texture1:getSize()
gfx.color.setBackground(gfx.color.RGBA8(200, 200, 200)) gfx.color.setBackground(gfx.color.RGBA8(200, 200, 200))
gfx.set3D(true) gfx.set3D(true)
@ -66,7 +67,7 @@ while ctr.run() do
gfx.text(5, 17, "Hello world, from Lua ! éàçù", 20, gfx.color.RGBA8(0, 0, 0)) gfx.text(5, 17, "Hello world, from Lua ! éàçù", 20, gfx.color.RGBA8(0, 0, 0))
gfx.text(5, 50, "Time: "..os.date()) gfx.text(5, 50, "Time: "..os.date())
texture1:draw(280, 80, angle); texture1:draw(280, 80, angle, tWidth/2, tHeight/2);
local cx, cy = hid.circle() local cx, cy = hid.circle()
gfx.rectangle(40, 90, 60, 60, 0, 0xDDDDDDFF) gfx.rectangle(40, 90, 60, 60, 0, 0xDDDDDDFF)

View file

@ -107,6 +107,30 @@ static int apt_getMenuAppID(lua_State *L) {
return 1; return 1;
} }
/***
Allow or not the system to enter sleep mode.
@function setSleepAllowed
@tparam boolean allowed `true` to allow, `false` to disallow
*/
static int apt_setSleepAllowed(lua_State *L) {
bool allowed = lua_toboolean(L, 1);
aptSetSleepAllowed(allowed);
return 0;
}
/***
Check if sleep mode is allowed.
@function isSleepAllowed
@treturn boolean `true` is allowed, false if not.
*/
static int apt_isSleepAllowed(lua_State *L) {
lua_pushboolean(L, aptIsSleepAllowed());
return 1;
}
static const struct luaL_Reg apt_lib[] = { static const struct luaL_Reg apt_lib[] = {
{"openSession", apt_openSession }, {"openSession", apt_openSession },
{"closeSession", apt_closeSession }, {"closeSession", apt_closeSession },
@ -117,6 +141,8 @@ static const struct luaL_Reg apt_lib[] = {
{"setStatusPower", apt_setStatusPower }, {"setStatusPower", apt_setStatusPower },
{"signalReadyForSleep", apt_signalReadyForSleep}, {"signalReadyForSleep", apt_signalReadyForSleep},
{"getMenuAppID", apt_getMenuAppID }, {"getMenuAppID", apt_getMenuAppID },
{"setSleepAllowed", apt_setSleepAllowed },
{"isSleepAllowed", apt_isSleepAllowed },
{NULL, NULL} {NULL, NULL}
}; };

View file

@ -189,4 +189,6 @@ void unload_font_lib(lua_State *L) {
if (luaL_testudata(L, -1, "LFont") != NULL) if (luaL_testudata(L, -1, "LFont") != NULL)
sftd_free_font(((font_userdata *)lua_touserdata(L, -1))->font); // Unload current font sftd_free_font(((font_userdata *)lua_touserdata(L, -1))->font); // Unload current font
lua_pop(L, 1);
} }

View file

@ -174,13 +174,14 @@ static int httpc_downloadData(lua_State *L) {
ret = httpcDownloadData(context, buff, size, NULL); ret = httpcDownloadData(context, buff, size, NULL);
if (ret != 0) { if (ret != 0) {
free(buff);
lua_pushnil(L); lua_pushnil(L);
lua_pushinteger(L, ret); lua_pushinteger(L, ret);
return 2; return 2;
} }
lua_pushstring(L, (char*)buff); lua_pushstring(L, (char*)buff);
//free(buff); FIXME we need to free this buffer at some point ? free(buff);
//lua_pushinteger(L, size); // only for test purposes. //lua_pushinteger(L, size); // only for test purposes.
return 1; return 1;
} }

View file

@ -45,13 +45,13 @@ static int ptm_shutdown(lua_State *L) {
/*** /***
Return the shell state. Return the shell state.
@function getShellState @function getShellState
@treturn number shell state @treturn boolean shell state, `true` if open, `false` if closed.
*/ */
static int ptm_getShellState(lua_State *L) { static int ptm_getShellState(lua_State *L) {
u8 out = 0; u8 out = 0;
PTMU_GetShellState(&out); PTMU_GetShellState(&out);
lua_pushinteger(L, out); lua_pushboolean(L, out);
return 1; return 1;
} }