From b47634f6992e98fb693f1c37cac1d168603f6891 Mon Sep 17 00:00:00 2001 From: Firew0lf Date: Tue, 15 Sep 2015 23:10:15 +0200 Subject: [PATCH] Fixed the documentation error with lzlib, Added gfx.get3D(), Enhanced the ir library errors returns. --- sdcard/3ds/ctruLua/openfile.lua | 4 +-- source/gfx.c | 16 ++++++++++-- source/ir.c | 45 ++++++++++++++++++++++++++++----- source/lzlib.c | 6 +++++ 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/sdcard/3ds/ctruLua/openfile.lua b/sdcard/3ds/ctruLua/openfile.lua index c913944..32a924e 100644 --- a/sdcard/3ds/ctruLua/openfile.lua +++ b/sdcard/3ds/ctruLua/openfile.lua @@ -26,7 +26,7 @@ return function(title, curdir, exts, type) local ret = nil -- Remember and set defaults - --local was3D = gfx.get3D() TODO: implement this thing in ctruLua + local was3D = gfx.get3D() local wasDefault = gfx.color.getDefault() local wasBackground = gfx.color.getBackground() local wasFont = gfx.font.getDefault() @@ -129,7 +129,7 @@ return function(title, curdir, exts, type) end -- Reset defaults - --gfx.set3D(was3D) + gfx.set3D(was3D) gfx.color.setDefault(wasDefault) gfx.color.setBackground(wasBackground) gfx.font.setDefault(wasFont) diff --git a/source/gfx.c b/source/gfx.c index f070648..be1310a 100644 --- a/source/gfx.c +++ b/source/gfx.c @@ -16,6 +16,7 @@ The `gfx` module. #include "font.h" bool isGfxInitialised = false; +bool is3DEnabled = false; //TODO: add a function for this in the ctrulib/sf2dlib. /*** The `ctr.gfx.color` module. @@ -103,13 +104,23 @@ Enable or disable the stereoscopic 3D on the top screen. @tparam boolean enable true to enable, false to disable */ static int gfx_set3D(lua_State *L) { - bool enable = lua_toboolean(L, 1); + is3DEnabled = lua_toboolean(L, 1); - sf2d_set_3D(enable); + sf2d_set_3D(is3DEnabled); return 0; } +/*** +Check whether or not the stereoscopic 3D is enabled. +@function get3D +@treturn boolean true if enabled, false if disabled +*/ +static int gfx_get3D(lua_State *L) { + lua_pushboolean(L, is3DEnabled); + return 1; +} + /*** Get free VRAM space. @function vramSpaceFree @@ -251,6 +262,7 @@ static const struct luaL_Reg gfx_lib[] = { { "render", gfx_render }, { "getFPS", gfx_getFPS }, { "set3D", gfx_set3D }, + { "get3D", gfx_get3D }, { "vramSpaceFree", gfx_vramSpaceFree }, { "line", gfx_line }, { "point", gfx_point }, diff --git a/source/ir.c b/source/ir.c index 40cd490..c58333c 100644 --- a/source/ir.c +++ b/source/ir.c @@ -43,6 +43,11 @@ Initialize the IR module. 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); @@ -62,9 +67,15 @@ Disable the IR module. @function shutdown */ static int ir_shutdown(lua_State *L) { - IRU_Shutdown(); + Result ret = IRU_Shutdown(); + if (ret) { + lua_pushboolean(L, false); + lua_pushinteger(L, ret); + return 2; + } - return 0; + lua_pushboolean(L, true); + return 1; } /*** @@ -77,7 +88,12 @@ static int ir_send(lua_State *L) { u8 *data = (u8*)luaL_checkstring(L, 1); u32 wait = lua_toboolean(L, 2); - IRU_SendData(data, sizeof(data), wait); + Result ret = IRU_SendData(data, sizeof(data), wait); + if (ret) { + lua_pushboolean(L, false); + lua_pushinteger(L, ret); + return 2; + } return 0; } @@ -89,12 +105,17 @@ Receive some data from the IR module. @tparam[opt=false] boolean wait wait until the data is received */ static int ir_receive(lua_State *L) { - u32 size = luaL_optinteger(L, 1, 0x800); + u32 size = luaL_optinteger(L, 1, bufferSize); u32 wait = lua_toboolean(L, 2); u8 *data = 0; u32 *transfercount = 0; - IRU_RecvData(data, size, 0x00, transfercount, wait); + Result ret = IRU_RecvData(data, size, 0x00, transfercount, wait); + if (ret) { + lua_pushboolean(L, false); + lua_pushinteger(L, ret); + return 2; + } lua_pushstring(L, (const char *)data); @@ -109,7 +130,12 @@ Set the bitrate of the communication. static int ir_setBitRate(lua_State *L) { u8 bitrate = luaL_checkinteger(L, 1); - IRU_SetBitRate(bitrate); + Result ret = IRU_SetBitRate(bitrate); + if (ret) { + lua_pushboolean(L, false); + lua_pushinteger(L, ret); + return 2; + } return 0; } @@ -122,7 +148,12 @@ Return the actual bitrate of the communication. static int ir_getBitRate(lua_State *L) { u8 bitrate = 0; - IRU_GetBitRate(&bitrate); + Result ret = IRU_GetBitRate(&bitrate); + if (ret) { + lua_pushboolean(L, false); + lua_pushinteger(L, ret); + return 2; + } lua_pushinteger(L, bitrate); diff --git a/source/lzlib.c b/source/lzlib.c index b73dee1..d045b1c 100644 --- a/source/lzlib.c +++ b/source/lzlib.c @@ -1,3 +1,9 @@ +/*** +The `fs.lzlib` module. See https://github.com/LuaDist/lzlib for informations and documentation. +@module ctr.fs.lzlib +@usage local lzlib = require("ctr.fs.lzlib") +*/ + /************************************************************************ * Author : Tiago Dionizio * * Library : lzlib - Lua 5 interface to access zlib library functions *