Skip to content

Commit

Permalink
Fixed the documentation error with lzlib, Added gfx.get3D(), Enhanced…
Browse files Browse the repository at this point in the history
… the ir library errors returns.
  • Loading branch information
firew0lf committed Sep 15, 2015
1 parent 22bcc3e commit b47634f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
4 changes: 2 additions & 2 deletions sdcard/3ds/ctruLua/openfile.lua
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions source/gfx.c
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 },
Expand Down
45 changes: 38 additions & 7 deletions source/ir.c
Expand Up @@ -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);
Expand All @@ -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;
}

/***
Expand All @@ -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;
}
Expand All @@ -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);

Expand All @@ -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;
}
Expand All @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions 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 <tiago.dionizio@gmail.com> *
* Library : lzlib - Lua 5 interface to access zlib library functions *
Expand Down

0 comments on commit b47634f

Please sign in to comment.