Skip to content

Commit

Permalink
Added the RC_DISABLE_LUA macro to compile rcheevos without Lua support
Browse files Browse the repository at this point in the history
  • Loading branch information
leiradel committed Sep 29, 2018
1 parent 2267068 commit a217be7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
19 changes: 19 additions & 0 deletions src/rcheevos/operand.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <stdlib.h>
#include <ctype.h>

#ifndef RC_DISABLE_LUA

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -14,6 +16,8 @@ extern "C" {
}
#endif

#endif /* RC_DISABLE_LUA */

static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, lua_State* L, int funcs_ndx) {
const char* aux = *memaddr;
const char* id;
Expand All @@ -32,6 +36,8 @@ static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, lua_St
aux++;
}

#ifndef RC_DISABLE_LUA

if (L != 0) {
if (!lua_istable(L, funcs_ndx)) {
return RC_INVALID_LUA_OPERAND;
Expand All @@ -48,6 +54,8 @@ static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, lua_St
self->function_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}

#endif /* RC_DISABLE_LUA */

self->type = RC_OPERAND_LUA;
*memaddr = aux;
return RC_OK;
Expand Down Expand Up @@ -288,6 +296,8 @@ int rc_parse_operand(rc_operand_t* self, const char** memaddr, int is_trigger, l
}
}

#ifndef RC_DISABLE_LUA

typedef struct {
rc_peek_t peek;
void* ud;
Expand All @@ -305,8 +315,13 @@ static int rc_luapeek(lua_State* L) {
return 1;
}

#endif /* RC_DISABLE_LUA */

unsigned rc_evaluate_operand(rc_operand_t* self, rc_peek_t peek, void* ud, lua_State* L) {
#ifndef RC_DISABLE_LUA
rc_luapeek_t luapeek;
#endif /* RC_DISABLE_LUA */

unsigned value = 0;

switch (self->type) {
Expand All @@ -319,6 +334,8 @@ unsigned rc_evaluate_operand(rc_operand_t* self, rc_peek_t peek, void* ud, lua_S
return 0;

case RC_OPERAND_LUA:
#ifndef RC_DISABLE_LUA

if (L != 0) {
lua_rawgeti(L, LUA_REGISTRYINDEX, self->function_ref);
lua_pushcfunction(L, rc_luapeek);
Expand All @@ -340,6 +357,8 @@ unsigned rc_evaluate_operand(rc_operand_t* self, rc_peek_t peek, void* ud, lua_S
lua_pop(L, 1);
}

#endif /* RC_DISABLE_LUA */

break;

case RC_OPERAND_ADDRESS:
Expand Down
20 changes: 10 additions & 10 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ LUA_SRC=lua/src
OBJ=$(RC_SRC)/trigger.o $(RC_SRC)/condset.o $(RC_SRC)/condition.o $(RC_SRC)/operand.o \
$(RC_SRC)/term.o $(RC_SRC)/expression.o $(RC_SRC)/value.o $(RC_SRC)/lboard.o \
$(RC_SRC)/alloc.o $(RC_SRC)/format.o \
$(RC_URL_SRC)/url.o \
$(LUA_SRC)/lapi.o $(LUA_SRC)/lcode.o $(LUA_SRC)/lctype.o $(LUA_SRC)/ldebug.o \
$(LUA_SRC)/ldo.o $(LUA_SRC)/ldump.o $(LUA_SRC)/lfunc.o $(LUA_SRC)/lgc.o $(LUA_SRC)/llex.o \
$(LUA_SRC)/lmem.o $(LUA_SRC)/lobject.o $(LUA_SRC)/lopcodes.o $(LUA_SRC)/lparser.o \
$(LUA_SRC)/lstate.o $(LUA_SRC)/lstring.o $(LUA_SRC)/ltable.o $(LUA_SRC)/ltm.o \
$(LUA_SRC)/lundump.o $(LUA_SRC)/lvm.o $(LUA_SRC)/lzio.o $(LUA_SRC)/lauxlib.o \
$(LUA_SRC)/lbaselib.o $(LUA_SRC)/lbitlib.o $(LUA_SRC)/lcorolib.o $(LUA_SRC)/ldblib.o \
$(LUA_SRC)/liolib.o $(LUA_SRC)/lmathlib.o $(LUA_SRC)/loslib.o $(LUA_SRC)/lstrlib.o \
$(LUA_SRC)/ltablib.o $(LUA_SRC)/lutf8lib.o $(LUA_SRC)/loadlib.o $(LUA_SRC)/linit.o \
test.o
$(RC_URL_SRC)/url.o \
$(LUA_SRC)/lapi.o $(LUA_SRC)/lcode.o $(LUA_SRC)/lctype.o $(LUA_SRC)/ldebug.o \
$(LUA_SRC)/ldo.o $(LUA_SRC)/ldump.o $(LUA_SRC)/lfunc.o $(LUA_SRC)/lgc.o $(LUA_SRC)/llex.o \
$(LUA_SRC)/lmem.o $(LUA_SRC)/lobject.o $(LUA_SRC)/lopcodes.o $(LUA_SRC)/lparser.o \
$(LUA_SRC)/lstate.o $(LUA_SRC)/lstring.o $(LUA_SRC)/ltable.o $(LUA_SRC)/ltm.o \
$(LUA_SRC)/lundump.o $(LUA_SRC)/lvm.o $(LUA_SRC)/lzio.o $(LUA_SRC)/lauxlib.o \
$(LUA_SRC)/lbaselib.o $(LUA_SRC)/lbitlib.o $(LUA_SRC)/lcorolib.o $(LUA_SRC)/ldblib.o \
$(LUA_SRC)/liolib.o $(LUA_SRC)/lmathlib.o $(LUA_SRC)/loslib.o $(LUA_SRC)/lstrlib.o \
$(LUA_SRC)/ltablib.o $(LUA_SRC)/lutf8lib.o $(LUA_SRC)/loadlib.o $(LUA_SRC)/linit.o \
test.o

all: test

Expand Down
6 changes: 5 additions & 1 deletion test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2065,9 +2065,11 @@ static void test_lboard(void) {
static void test_lua(void) {
{
/*------------------------------------------------------------------------
TestJson
TestLua
------------------------------------------------------------------------*/

#ifndef RC_DISABLE_LUA

lua_State* L;
const char* luacheevo = "return { test = function(peek, ud) return peek(0, 4, ud) end }";
unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56};
Expand All @@ -2087,6 +2089,8 @@ static void test_lua(void) {

trigger = rc_parse_trigger(buffer, "@test=0xX0", L, 1);
assert(rc_test_trigger(trigger, peek, &memory, L) != 0);

#endif /* RC_DISABLE_LUA */
}
}

Expand Down

0 comments on commit a217be7

Please sign in to comment.