1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-28 00:39:30 +00:00

Updated all the libs, added citro3d, added ctr.swkbd (WIP, untested)

This commit is contained in:
Firew0lf 2016-08-05 17:30:24 +02:00
parent 68a44645f7
commit 49c87e5526
97 changed files with 7341 additions and 944 deletions

View file

@ -136,6 +136,13 @@ The `ctr.uds` module.
void load_uds_lib(lua_State *L);
void unload_uds_lib(lua_State *L);
/***
The `ctr.swkbd` module.
@table swkbd
@see ctr.swkbd
*/
void load_swkbd_lib(lua_State *L);
/***
Return whether or not the program should continue.
@function run
@ -207,6 +214,7 @@ struct { char *name; void (*load)(lua_State *L); void (*unload)(lua_State *L); }
{ "mic", load_mic_lib, NULL },
{ "thread", load_thread_lib, NULL },
{ "uds", load_uds_lib, unload_uds_lib },
{ "swkbd", load_swkbd_lib, NULL },
{ NULL, NULL, NULL }
};

View file

@ -655,26 +655,9 @@ static int gfx_target___index(lua_State *L) {
luaL_getmetatable(L, "LTexture");
lua_setmetatable(L, -2);
texture->texture = &(target->target->texture);
texture->scaleX = 1.0f;
texture->scaleY = 1.0f;
texture->blendColor = 0xffffffff;
// TODO: return an usable texture
return 1;
} else if (strcmp(name, "duck") == 0) {
sf2d_rendertarget *target = sf2d_create_rendertarget(64, 64);
for(int i=0;;i++) {
sf2d_clear_target(target, 0xff000000);
sf2d_start_frame_target(target);
sf2d_draw_fill_circle(i%380, i%200, 10, 0xff0000ff);
sf2d_end_frame();
//sf2d_texture_tile32(&target->texture);
sf2d_start_frame(GFX_TOP, GFX_LEFT);
sf2d_draw_texture(&target->texture, 10, 10);
sf2d_end_frame();
sf2d_swapbuffers();
}
} else {
for (u8 i=0;target_methods[i].name;i++) {
if (strcmp(target_methods[i].name, name) == 0) {

204
source/swkbd.c Normal file
View file

@ -0,0 +1,204 @@
/***
The `swkbd` module.
@module ctr.swkbd
@usage local swkbd = require("ctr.swkbd")
*/
#include <3ds/types.h>
#include <3ds/applets/swkbd.h>
#include <lapi.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <malloc.h>
// functions
/***
Create a software keyboard.
@function keyboard
@tparam[opt=TYPE_NORMAL] TYPE type keyboard type.
@tparam[opt=2] integer buttons number of buttons, can be 1, 2 or 3. Will default to 2 if the number isn't 1, 2 or 3
@tparam[opt=max] integer maxLength maximum length of the text. (maximum 65000)
@treturn keyboard a software keyboard object
*/
static int swkbd_keyboard(lua_State *L) {
SwkbdType type = luaL_optinteger(L, 1, SWKBD_TYPE_NORMAL);
int buttons = luaL_optinteger(L, 2, 2);
int maxLength = luaL_optinteger(L, 3, -1);
SwkbdState *keyboard = lua_newuserdata(L, sizeof(*keyboard));
luaL_getmetatable(L, "LKeyboard");
lua_setmetatable(L, -2);
swkbdInit(keyboard, type, buttons, maxLength);
return 1;
}
// methods
/***
Keyboard object
@section object
*/
/***
Launch the keyboard applet.
@function :launch
@tparam[opt=max] integer maxLength maximum text length (max 65000)
@treturn[1] string text (UTF-8)
@treturn[1] integer button pressed (1, 2 or 3)
@treturn[2] nil
@treturn[2] string error. In case of an "OUTOFMEM" error, this function will throw an error instead of returning.
*/
static int keyboard_launch(lua_State *L) {
SwkbdState *keyboard = luaL_checkudata(L, 1, "LKeyboard");
int length = luaL_optinteger(L, 2, 65000);
char* buff = malloc(length);
SwkbdButton button = swkbdInputText(keyboard, buff, length);
if (button<0) {
free(buff);
lua_pushnil(L);
switch (button) {
case SWKBD_NONE:
lua_pushstring(L, "That wasn't supposed to happen.");
break;
case SWKBD_INVALID_INPUT:
lua_pushstring(L, "Invalid parameters.");
break;
case SWKBD_OUTOFMEM:
luaL_error(L, "Out of memory.");
break;
default:
lua_pushfstring(L, "Unexpected error: %d.", button);
break;
}
return 2;
}
lua_pushstring(L, buff);
free(buff);
lua_pushinteger(L, button);
return 2;
}
/***
Set the initial text in the textbox.
@function :setInitialText
@tparam[opt=""] string text initial text
*/
static int keyboard_setInitialText(lua_State *L) {
SwkbdState *keyboard = luaL_checkudata(L, 1, "LKeyboard");
const char* text = luaL_optstring(L, 2, "");
swkbdSetInitialText(keyboard, text);
return 0;
}
/***
Set the text displayed in the textbox when it's empty.
@function :setHintText
@tparam[opt=""] string text hint text
*/
static int keyboard_setHintText(lua_State *L) {
SwkbdState *keyboard = luaL_checkudata(L, 1, "LKeyboard");
const char* text = luaL_optstring(L, 2, "");
swkbdSetHintText(keyboard, text);
return 0;
}
////////////////////
static const struct luaL_Reg swkbd_lib[] = {
{"keyboard", swkbd_keyboard},
{NULL, NULL}
};
static const struct luaL_Reg swkbd_object_methods[] = {
{"launch", keyboard_launch},
{"setInitialText", keyboard_setInitialText},
{"setHintText", keyboard_setHintText},
{NULL, NULL}
};
/***
Constants
@section constants
*/
struct { char *name; int value; } swkbd_constants[] = {
/***
@field TYPE_NORMAL
*/
{"TYPE_NORMAL", SWKBD_TYPE_NORMAL},
/***
@field TYPE_QWERTY
*/
{"TYPE_QWERTY", SWKBD_TYPE_QWERTY},
/***
@field TYPE_NUMPAD
*/
{"TYPE_NUMPAD", SWKBD_TYPE_NUMPAD},
/***
@field TYPE_WESTERN
*/
{"TYPE_WESTERN", SWKBD_TYPE_WESTERN},
/***
@field ANYTHING
*/
{"ANYTHING", SWKBD_ANYTHING},
/***
@field NOTEMPTY
*/
{"NOTEMPTY", SWKBD_NOTEMPTY},
/***
@field NOTEMPTY_NOTBLANK
*/
{"NOTEMPTY_NOTBLANK", SWKBD_NOTEMPTY_NOTBLANK},
/***
@field NOTBLANK_NOTEMPTY
*/
{"NOTBLANK_NOTEMPTY", SWKBD_NOTBLANK_NOTEMPTY},
/***
@field NOTBLANK
*/
{"NOTBLANK", SWKBD_NOTBLANK},
/***
@field FIXEDLEN
*/
{"FIXEDLEN", SWKBD_FIXEDLEN},
{NULL, 0}
};
int luaopen_swkbd_lib(lua_State *L) {
luaL_newmetatable(L, "LKeyboard");
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
luaL_setfuncs(L, swkbd_object_methods, 0);
luaL_newlib(L, swkbd_lib);
for (int i = 0; swkbd_constants[i].name; i++) {
lua_pushinteger(L, swkbd_constants[i].value);
lua_setfield(L, -2, swkbd_constants[i].name);
}
return 1;
}
void load_swkbd_lib(lua_State *L) {
luaL_requiref(L, "ctr.swkbd", luaopen_swkbd_lib, false);
}

View file

@ -175,7 +175,8 @@ static int texture_drawPart(lua_State *L) {
float hotspotX = luaL_optnumber(L, 9, 0.0f);
float hotspotY = luaL_optnumber(L, 10, 0.0f);
sf2d_draw_texture_part_rotate_scale_hotspot_blend(texture->texture, x, y, rad, sx, sy, w, h, texture->scaleX, texture->scaleY, hotspotX, hotspotY, texture->blendColor);
//sf2d_draw_texture_part_rotate_scale_hotspot_blend(texture->texture, x, y, rad, sx, sy, w, h, texture->scaleX, texture->scaleY, hotspotX, hotspotY, texture->blendColor); // TODO: fix
sf2d_draw_texture_part_rotate_scale_blend(texture->texture, x, y, rad, sx, sy, w, h, texture->scaleX, texture->scaleY, texture->blendColor);
return 0;
}
@ -409,11 +410,6 @@ struct { char *name; int value; } texture_constants[] = {
*/
{"PLACE_VRAM", SF2D_PLACE_VRAM},
/***
Constant used to select a temporary RAM pool. Don't use it.
@field PLACE_TEMP
*/
{"PLACE_TEMP", SF2D_PLACE_TEMP},
/***
Constant used to select the PNG type.
@field TYPE_PNG
*/

View file

@ -22,6 +22,8 @@ typedef struct {
Thread thread;
const char *code;
char *error;
void* pool;
int poolSize; // in bytes
} thread_userdata;
void entryPoint(void *thread) {