Skip to content

Commit

Permalink
Added references to port param for Controls functions in doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinnegatamante committed Apr 1, 2021
1 parent 80f4641 commit 48c5eda
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 45 deletions.
12 changes: 9 additions & 3 deletions doc/luaControls.cpp
Expand Up @@ -53,9 +53,11 @@ class Controls {
* pad = Controls.read()
* @endcode
*
* @param port - Device port to use <b>(optional)</b>.
*
* @return Bitmask of the pressed buttons.
*/
int read(void);
int read(int port);

/**
* Read left analog state.
Expand All @@ -66,9 +68,11 @@ class Controls {
* x, y = Controls.readLeftAnalog()
* @endcode
*
* @param port - Device port to use <b>(optional)</b>.
*
* @return X and Y values of left analog.
*/
int[] readLeftAnalog(void);
int[] readLeftAnalog(int port);

/**
* Read right analog state.
Expand All @@ -79,9 +83,11 @@ class Controls {
* x, y = Controls.readRightAnalog()
* @endcode
*
* @param port - Device port to use <b>(optional)</b>.
*
* @return X and Y values of right analog.
*/
int[] readRightAnalog(void);
int[] readRightAnalog(int port);

/**
* Read touchscreen state.
Expand Down
84 changes: 42 additions & 42 deletions source/luaControls.cpp
Expand Up @@ -42,15 +42,15 @@ static bool sensors_enabled = false;

static int lua_readC(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0 && argc != 1) return luaL_error(L, "wrong number of arguments.");
#endif
#endif
int port = 0;
if (argc == 1){
port = luaL_checkinteger(L, 1);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (port > 5) return luaL_error(L, "wrong port number.");
#endif
#endif
}
SceCtrlData pad;
sceCtrlPeekBufferPositive(port, &pad, 1);
Expand All @@ -60,15 +60,15 @@ static int lua_readC(lua_State *L){

static int lua_readleft(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0 && argc != 1) return luaL_error(L, "wrong number of arguments.");
#endif
#endif
int port = 0;
if (argc == 1){
port = luaL_checkinteger(L, 1);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (port > 5) return luaL_error(L, "wrong port number.");
#endif
#endif
}
SceCtrlData pad;
sceCtrlPeekBufferPositive(port, &pad, 1);
Expand All @@ -79,15 +79,15 @@ static int lua_readleft(lua_State *L){

static int lua_readright(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0 && argc != 1) return luaL_error(L, "wrong number of arguments.");
#endif
#endif
int port = 0;
if (argc == 1){
port = luaL_checkinteger(L, 1);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (port > 5) return luaL_error(L, "wrong port number.");
#endif
#endif
}
SceCtrlData pad;
sceCtrlPeekBufferPositive(port, &pad, 1);
Expand All @@ -98,9 +98,9 @@ static int lua_readright(lua_State *L){

static int lua_check(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 2) return luaL_error(L, "wrong number of arguments.");
#endif
#endif
int pad = luaL_checkinteger(L, 1);
int button = luaL_checkinteger(L, 2);
lua_pushboolean(L, (pad & button));
Expand All @@ -121,13 +121,13 @@ static int lua_touchpad(lua_State *L){

static int lua_rumble(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 3) return luaL_error(L, "wrong number of arguments.");
#endif
#endif
int port = luaL_checkinteger(L, 1);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (port > 5) return luaL_error(L, "wrong port number.");
#endif
#endif
if (port == 0) port = 1;
uint8_t int_small = luaL_checkinteger(L, 2);
uint8_t int_large = luaL_checkinteger(L, 3);
Expand All @@ -139,13 +139,13 @@ static int lua_rumble(lua_State *L){

static int lua_lightbar(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 2) return luaL_error(L, "wrong number of arguments.");
#endif
#endif
int port = luaL_checkinteger(L, 1);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (port > 5) return luaL_error(L, "wrong port number.");
#endif
#endif
if (port == 0) port = 1;
uint32_t color = luaL_checkinteger(L, 2);
sceCtrlSetLightBar(port, color & 0xFF, (color>>8) & 0xFF, (color>>16) & 0xFF);
Expand All @@ -154,9 +154,9 @@ static int lua_lightbar(lua_State *L){

static int lua_touchpad2(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0) return luaL_error(L, "wrong number of arguments.");
#endif
#endif
SceTouchData touch;
sceTouchPeek(SCE_TOUCH_PORT_BACK, &touch, 1);
for (SceUInt32 i=0;i<touch.reportNum;i++){
Expand All @@ -168,27 +168,27 @@ static int lua_touchpad2(lua_State *L){

static int lua_lock(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0) return luaL_error(L, "wrong number of arguments.");
#endif
#endif
sceShellUtilLock((SceShellUtilLockType)(SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN | SCE_SHELL_UTIL_LOCK_TYPE_QUICK_MENU));
return 0;
}

static int lua_unlock(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0) return luaL_error(L, "wrong number of arguments.");
#endif
#endif
sceShellUtilUnlock((SceShellUtilLockType)(SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN | SCE_SHELL_UTIL_LOCK_TYPE_QUICK_MENU));
return 0;
}

static int lua_gettype(lua_State *L) {
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0) return luaL_error(L, "wrong number of arguments");
#endif
#endif
SceCtrlPortInfo pinfo;
sceCtrlGetControllerPortInfo(&pinfo);
lua_newtable(L);
Expand All @@ -207,10 +207,10 @@ static int lua_gettype(lua_State *L) {

static int lua_headset(lua_State *L) {
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0) return luaL_error(L, "wrong number of arguments");
if (!unsafe_mode) return luaL_error(L, "this function requires unsafe mode");
#endif
#endif
SceCtrlData pad;
sceCtrlPeekBufferPositive(0, &pad, 1);
lua_pushboolean(L, (pad.buttons & SCE_CTRL_HEADPHONE));
Expand All @@ -219,10 +219,10 @@ static int lua_headset(lua_State *L) {

static int lua_accel(lua_State *L) {
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0) return luaL_error(L, "wrong number of arguments");
if (!sensors_enabled) return luaL_error(L, "you must enable sensors reading to use this function.");
#endif
#endif
SceMotionSensorState sensor;
sceMotionGetSensorState(&sensor, 1);
lua_pushnumber(L, sensor.accelerometer.x);
Expand All @@ -233,10 +233,10 @@ static int lua_accel(lua_State *L) {

static int lua_gyro(lua_State *L) {
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0) return luaL_error(L, "wrong number of arguments");
if (!sensors_enabled) return luaL_error(L, "you must enable sensors reading to use this function.");
#endif
#endif
SceMotionSensorState sensor;
sceMotionGetSensorState(&sensor, 1);
lua_pushnumber(L, sensor.gyro.x);
Expand All @@ -247,9 +247,9 @@ static int lua_gyro(lua_State *L) {

static int lua_enablesensors(lua_State *L) {
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0) return luaL_error(L, "wrong number of arguments");
#endif
#endif
if (!sensors_enabled){
sceMotionStartSampling();
sceMotionMagnetometerOn();
Expand All @@ -260,9 +260,9 @@ static int lua_enablesensors(lua_State *L) {

static int lua_disablesensors(lua_State *L) {
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0) return luaL_error(L, "wrong number of arguments");
#endif
#endif
if (sensors_enabled){
sceMotionMagnetometerOff();
sceMotionStopSampling();
Expand All @@ -273,9 +273,9 @@ static int lua_disablesensors(lua_State *L) {

static int lua_getenter(lua_State *L) {
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
#ifndef SKIP_ERROR_HANDLING
if (argc != 0) return luaL_error(L, "wrong number of arguments");
#endif
#endif
int val;
sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_ENTER_BUTTON, &val);
if (val == 0) lua_pushinteger(L, SCE_CTRL_CIRCLE);
Expand Down

0 comments on commit 48c5eda

Please sign in to comment.