Commit 48f06d85 authored by Jean-Andre Santoni's avatar Jean-Andre Santoni
Browse files

Fix indentation

parent f6e37a75
......@@ -31,13 +31,13 @@ void lutro_event_init()
*/
int event_quit(lua_State *L)
{
int n = lua_gettop(L);
if (n > 1) {
return luaL_error(L, "lutro.event.quit requires 0 or 1 arguments, %d given.", n);
}
int n = lua_gettop(L);
if (n > 1) {
return luaL_error(L, "lutro.event.quit requires 0 or 1 arguments, %d given.", n);
}
// Quit, ignoring the exit status.
lutro_shutdown_game();
// Quit, ignoring the exit status.
lutro_shutdown_game();
return 0;
return 0;
}
......@@ -51,29 +51,29 @@ void lutro_joystick_init()
void lutro_joystickevent(lua_State* L)
{
int i, u;
int16_t state;
int i, u;
int16_t state;
// Loop through each joystick.
for (i = 0; i < 4; i++) {
// Loop through each button.
for (u = 0; u < 14; u++) {
// Loop through each joystick.
for (i = 0; i < 4; i++) {
// Loop through each button.
for (u = 0; u < 14; u++) {
// Retrieve the state of the button.
state = settings.input_cb(i, RETRO_DEVICE_JOYPAD, 0, u);
// Check if there's a change of state.
if (joystick_cache[i][u] != state) {
joystick_cache[i][u] = state;
// If the button was pressed, invoke the callback.
if (state > 0) {
lutro_joystickInvokeJoystickEvent(L, "joystickpressed", i, u);
}
else {
lutro_joystickInvokeJoystickEvent(L, "joystickreleased", i, u);
}
joystick_cache[i][u] = state;
// If the button was pressed, invoke the callback.
if (state > 0) {
lutro_joystickInvokeJoystickEvent(L, "joystickpressed", i, u);
}
else {
lutro_joystickInvokeJoystickEvent(L, "joystickreleased", i, u);
}
}
}
}
}
}
}
/**
......@@ -81,26 +81,26 @@ void lutro_joystickevent(lua_State* L)
* Invokes lutro.joystickreleased(joystick, button)
*/
void lutro_joystickInvokeJoystickEvent(lua_State* L, char* eventName, int joystick, int button) {
lua_getglobal(L, "lutro");
lua_getfield(L, -1, eventName);
if (lua_isfunction(L, -1))
{
// Add the first argument (the joystick number).
// TODO: Switch to using Joystick objects.
lua_pushnumber(L, joystick);
// Add the second argument (the joystick key).
lua_pushnumber(L, button);
// Call the event callback.
if (lua_pcall(L, 2, 0, -5))
{
fprintf(stderr, "%s\n", lua_tostring(L, -1));
lua_pop(L, 1);
}
} else {
lua_pop(L, 1);
}
lua_getglobal(L, "lutro");
lua_getfield(L, -1, eventName);
if (lua_isfunction(L, -1))
{
// Add the first argument (the joystick number).
// TODO: Switch to using Joystick objects.
lua_pushnumber(L, joystick);
// Add the second argument (the joystick key).
lua_pushnumber(L, button);
// Call the event callback.
if (lua_pcall(L, 2, 0, -5))
{
fprintf(stderr, "%s\n", lua_tostring(L, -1));
lua_pop(L, 1);
}
} else {
lua_pop(L, 1);
}
}
/**
......@@ -110,15 +110,15 @@ void lutro_joystickInvokeJoystickEvent(lua_State* L, char* eventName, int joysti
*/
int joystick_getJoystickCount(lua_State *L)
{
int n = lua_gettop(L);
if (n > 0) {
return luaL_error(L, "lutro.joystick.getJoystickCount requires no arguments, %d given.", n);
}
int n = lua_gettop(L);
if (n > 0) {
return luaL_error(L, "lutro.joystick.getJoystickCount requires no arguments, %d given.", n);
}
// TODO: Query libretro to see device capacities of all joysticks.
lua_pushnumber(L, 4);
// TODO: Query libretro to see device capacities of all joysticks.
lua_pushnumber(L, 4);
return 1;
return 1;
}
/**
......@@ -128,21 +128,21 @@ int joystick_getJoystickCount(lua_State *L)
*/
int joystick_isDown(lua_State *L)
{
int n = lua_gettop(L);
if (n != 2) {
return luaL_error(L, "lutro.joystick.isDown requires two arguments, %d given.", n);
}
int n = lua_gettop(L);
if (n != 2) {
return luaL_error(L, "lutro.joystick.isDown requires two arguments, %d given.", n);
}
bool output;
bool output;
int joystick = luaL_checknumber(L, 1);
int button = luaL_checknumber(L, 2);
int joystick = luaL_checknumber(L, 1);
int button = luaL_checknumber(L, 2);
output = (bool) joystick_cache[joystick - 1][button - 1];
output = (bool) joystick_cache[joystick - 1][button - 1];
lua_pushboolean(L, output);
lua_pushboolean(L, output);
return 1;
return 1;
}
/**
......@@ -162,11 +162,11 @@ const char* joystick_retroToJoystick(unsigned joystickKey)
*/
int joystick_joystickToRetro(const char* retroKey)
{
unsigned id;
if (joystick_find_value(joystick_key_enum, retroKey, &id) == 0) {
return 0;
}
return id;
unsigned id;
if (joystick_find_value(joystick_key_enum, retroKey, &id) == 0) {
return 0;
}
return id;
}
/**
......
......@@ -224,26 +224,26 @@ void lutro_keyboardevent(lua_State* L)
*/
int keyboard_isDown(lua_State *L)
{
int n = lua_gettop(L);
if (n < 1) {
return luaL_error(L, "lutro.keyboard.isDown requires 1 or more arguments, %d given.", n);
}
int n = lua_gettop(L);
if (n < 1) {
return luaL_error(L, "lutro.keyboard.isDown requires 1 or more arguments, %d given.", n);
}
bool output = false;
unsigned i;
for (i = 0; i < n; i++) {
bool output = false;
unsigned i;
for (i = 0; i < n; i++) {
const char* buttonToCheck = luaL_checkstring(L, i + 1);
unsigned id;
if (!keyboard_find_value(keyboard_enum, buttonToCheck, &id))
return luaL_error(L, "invalid button");
if (keyboard_cache[id]) {
output = true;
break;
output = true;
break;
}
}
lua_pushboolean(L, output);
}
lua_pushboolean(L, output);
return 1;
return 1;
}
/**
......@@ -252,19 +252,19 @@ int keyboard_isDown(lua_State *L)
* https://love2d.org/wiki/love.keyboard.getScancodeFromKey
*/
int keyboard_getScancodeFromKey(lua_State *L) {
int n = lua_gettop(L);
if (n != 1) {
int n = lua_gettop(L);
if (n != 1) {
return luaL_error(L, "lutro.keyboard.getScancodeFromKey requires 1 argument, %d given.", n);
}
}
const char* buttonToCheck = luaL_checkstring(L, 1);
const char* buttonToCheck = luaL_checkstring(L, 1);
unsigned id;
if (!keyboard_find_value(keyboard_enum, buttonToCheck, &id))
return luaL_error(L, "invalid button");
lua_pushnumber(L, id);
unsigned id;
if (!keyboard_find_value(keyboard_enum, buttonToCheck, &id))
return luaL_error(L, "invalid button");
lua_pushnumber(L, id);
return 1;
return 1;
}
/**
* lutro.keyboard.getKeyFromScancode(key)
......@@ -272,16 +272,16 @@ int keyboard_getScancodeFromKey(lua_State *L) {
* https://love2d.org/wiki/love.keyboard.getKeyFromScancode
*/
int keyboard_getKeyFromScancode(lua_State *L) {
int n = lua_gettop(L);
if (n != 1) {
int n = lua_gettop(L);
if (n != 1) {
return luaL_error(L, "lutro.keyboard.getKeyFromScancode requires 1 argument, %d given.", n);
}
}
unsigned scancode = luaL_checknumber(L, 1);
const char* key = keyboard_find_name(keyboard_enum, scancode);
lua_pushstring(L, key);
unsigned scancode = luaL_checknumber(L, 1);
const char* key = keyboard_find_name(keyboard_enum, scancode);
lua_pushstring(L, key);
return 1;
return 1;
}
int keyboard_find_value(const struct key_int_const_map *map, const char *name, unsigned *value)
......
......@@ -116,55 +116,55 @@ static void dumpstack( lua_State* L )
#define LEVELS2 10 /* size of the second part of the stack */
static int db_errorfb (lua_State *L) {
int level;
int firstpart = 1; /* still before eventual `...' */
int arg = 0;
lua_State *L1 = L; /*getthread(L, &arg);*/
lua_Debug ar;
if (lua_isnumber(L, arg+2)) {
level = (int)lua_tointeger(L, arg+2);
lua_pop(L, 1);
}
else
level = (L == L1) ? 1 : 0; /* level 0 may be this own function */
if (lua_gettop(L) == arg)
lua_pushliteral(L, "");
else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */
else lua_pushliteral(L, "\n");
lua_pushliteral(L, "stack traceback:");
while (lua_getstack(L1, level++, &ar)) {
if (level > LEVELS1 && firstpart) {
/* no more than `LEVELS2' more levels? */
if (!lua_getstack(L1, level+LEVELS2, &ar))
level--; /* keep going */
else {
lua_pushliteral(L, "\n\t..."); /* too many levels */
while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */
level++;
int level;
int firstpart = 1; /* still before eventual `...' */
int arg = 0;
lua_State *L1 = L; /*getthread(L, &arg);*/
lua_Debug ar;
if (lua_isnumber(L, arg+2)) {
level = (int)lua_tointeger(L, arg+2);
lua_pop(L, 1);
}
else
level = (L == L1) ? 1 : 0; /* level 0 may be this own function */
if (lua_gettop(L) == arg)
lua_pushliteral(L, "");
else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */
else lua_pushliteral(L, "\n");
lua_pushliteral(L, "stack traceback:");
while (lua_getstack(L1, level++, &ar)) {
if (level > LEVELS1 && firstpart) {
/* no more than `LEVELS2' more levels? */
if (!lua_getstack(L1, level+LEVELS2, &ar))
level--; /* keep going */
else {
lua_pushliteral(L, "\n\t..."); /* too many levels */
while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */
level++;
}
firstpart = 0;
continue;
}
firstpart = 0;
continue;
}
lua_pushliteral(L, "\n\t");
lua_getinfo(L1, "Snl", &ar);
lua_pushfstring(L, "%s:", ar.short_src);
if (ar.currentline > 0)
lua_pushfstring(L, "%d:", ar.currentline);
if (*ar.namewhat != '\0') /* is there a name? */
lua_pushfstring(L, " in function " LUA_QS, ar.name);
else {
lua_pushliteral(L, "\n\t");
lua_getinfo(L1, "Snl", &ar);
lua_pushfstring(L, "%s:", ar.short_src);
if (ar.currentline > 0)
lua_pushfstring(L, "%d:", ar.currentline);
if (*ar.namewhat != '\0') /* is there a name? */
lua_pushfstring(L, " in function " LUA_QS, ar.name);
else {
if (*ar.what == 'm') /* main? */
lua_pushfstring(L, " in main chunk");
lua_pushfstring(L, " in main chunk");
else if (*ar.what == 'C' || *ar.what == 't')
lua_pushliteral(L, " ?"); /* C function or tail call */
lua_pushliteral(L, " ?"); /* C function or tail call */
else
lua_pushfstring(L, " in function <%s:%d>",
lua_pushfstring(L, " in function <%s:%d>",
ar.short_src, ar.linedefined);
}
lua_concat(L, lua_gettop(L) - arg);
}
lua_concat(L, lua_gettop(L) - arg);
return 1;
}
lua_concat(L, lua_gettop(L) - arg);
}
lua_concat(L, lua_gettop(L) - arg);
return 1;
}
static int dofile(lua_State *L, const char *path)
......
#include "lutro.h"
#include "lutro_math.h"
......
......@@ -119,12 +119,12 @@ void lutro_relpath_to_modname(char *outmod, const char *relpath)
* https://love2d.org/wiki/love.getVersion
*/
int lutro_getVersion(lua_State *L) {
lua_pushnumber(L, VERSION_MAJOR);
lua_pushnumber(L, VERSION_MINOR);
lua_pushnumber(L, VERSION_PATCH);
lua_pushstring(L, "Lutro");
lua_pushnumber(L, VERSION_MAJOR);
lua_pushnumber(L, VERSION_MINOR);
lua_pushnumber(L, VERSION_PATCH);
lua_pushstring(L, "Lutro");
return 4;
return 4;
}
#if LUA_VERSION_NUM < 502
......@@ -185,15 +185,15 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op)
int b = lua_absindex(L, index2);
int i = 0;
if (!lua_isnil(L, a) && !lua_isnil(L, b)) {
switch (op) {
case LUA_OPEQ: i = lua_equal(L, a, b); break;
case LUA_OPLT: i = lua_lessthan(L, a, b); break;
case LUA_OPLE: i = lua_lessthan(L, a, b) || lua_equal(L, a, b); break;
default: api_check2(L, 0, "invalid option");
}
}
return i;
if (!lua_isnil(L, a) && !lua_isnil(L, b)) {
switch (op) {
case LUA_OPEQ: i = lua_equal(L, a, b); break;
case LUA_OPLT: i = lua_lessthan(L, a, b); break;
case LUA_OPLE: i = lua_lessthan(L, a, b) || lua_equal(L, a, b); break;
default: api_check2(L, 0, "invalid option");
}
}
return i;
}
static int typeerror (lua_State *L, int narg, const char *tname)
......@@ -226,45 +226,45 @@ int l_not_implemented(lua_State *L)
int luax_insistglobal(lua_State *L, const char *k)
{
lua_getglobal(L, k);
lua_getglobal(L, k);
if (!lua_istable(L, -1))
{
lua_pop(L, 1); // Pop the non-table.
lua_newtable(L);
lua_pushvalue(L, -1);
lua_setglobal(L, k);
}
if (!lua_istable(L, -1))
{
lua_pop(L, 1); // Pop the non-table.
lua_newtable(L);
lua_pushvalue(L, -1);
lua_setglobal(L, k);
}
return 1;
return 1;
}
int luax_c_insistglobal(lua_State *L, const char *k)
{
return luax_insistglobal(L, k);
return luax_insistglobal(L, k);
}
void luax_register(lua_State *L, const char *name, const luaL_Reg *l)
{
if (name)
lua_newtable(L);
luax_setfuncs(L, l);
if (name)
{
lua_pushvalue(L, -1);
lua_setglobal(L, name);
}
if (name)
lua_newtable(L);
luax_setfuncs(L, l);
if (name)
{
lua_pushvalue(L, -1);
lua_setglobal(L, name);
}
}
void luax_setfuncs(lua_State *L, const luaL_Reg *l)
{
if (!l)
return;
for (; l->name; l++)
{
lua_pushcfunction(L, l->func);
lua_setfield(L, -2, l->name);
}
if (!l)
return;
for (; l->name; l++)
{
lua_pushcfunction(L, l->func);
lua_setfield(L, -2, l->name);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment