From 568c8829db2f886921c7592cadbadbf4241127b6 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 27 Apr 2014 16:48:07 +1000 Subject: Centralise the PACKAGE_* stuff, move our libraries to lib, and shuffle stuff to suit. --- src/GuiLua/GuiLua.h | 23 +--- src/GuiLua/build.lua | 4 +- src/GuiLua/skang.c | 6 +- src/GuiLua/test.sh | 2 +- src/LuaSL/LuaSL_compile.c | 4 +- src/LuaSL/LuaSL_test.c | 8 +- src/LuaSL/build.lua | 9 ++ src/LuaSL/test.sh | 2 +- src/extantz/extantz.c | 21 ++- src/extantz/extantz.h | 8 +- src/libraries/LumbrJack.c | 85 +++++++++++++ src/libraries/LumbrJack.h | 38 ++++++ src/libraries/Runnr.c | 318 ++++++++++++++++++++++++++++++++++++++++++++++ src/libraries/Runnr.h | 15 +++ src/libraries/SledjHamr.c | 23 ++++ src/libraries/SledjHamr.h | 14 ++ src/libraries/build.lua | 33 +++++ 17 files changed, 559 insertions(+), 54 deletions(-) create mode 100644 src/libraries/LumbrJack.c create mode 100644 src/libraries/LumbrJack.h create mode 100644 src/libraries/Runnr.c create mode 100644 src/libraries/Runnr.h create mode 100644 src/libraries/SledjHamr.c create mode 100644 src/libraries/SledjHamr.h create mode 100755 src/libraries/build.lua (limited to 'src') diff --git a/src/GuiLua/GuiLua.h b/src/GuiLua/GuiLua.h index 95353fb..2dd77ba 100644 --- a/src/GuiLua/GuiLua.h +++ b/src/GuiLua/GuiLua.h @@ -1,27 +1,8 @@ - -#define EFL_API_OVERRIDE 1 -/* Enable access to unstable EFL API that are still in beta */ -#define EFL_BETA_API_SUPPORT 1 -/* Enable access to unstable EFL EO API. */ -#define EFL_EO_API_SUPPORT 1 - -#include -#include - -#include - -// This got left out. -//EAPI Evas_3D_Scene *evas_3d_scene_add(Evas *e); - - -#include -#include -#include -#include - +#include "SledjHamr.h" #include "LumbrJack.h" #include "Runnr.h" + typedef struct _globals globals; diff --git a/src/GuiLua/build.lua b/src/GuiLua/build.lua index 16f4153..169e198 100755 --- a/src/GuiLua/build.lua +++ b/src/GuiLua/build.lua @@ -15,9 +15,9 @@ end LDFLAGS = '-L ' .. dir .. ' ' .. LDFLAGS -removeFiles(dir, {'test_c.so', 'GuiLua.o', '../../libraries/libGuiLua.so', '../../skang'}) +removeFiles(dir, {'test_c.so', 'GuiLua.o', lib_d .. '/libGuiLua.so', '../../skang'}) runCommand('C modules', dir, 'gcc ' .. CFLAGS .. ' -fPIC -shared -o test_c.so test_c.c') runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -fPIC -c GuiLua.c') -runCommand('C libraries', dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libGuiLua.so -o ../../libraries/libGuiLua.so GuiLua.o') +runCommand('C libraries', dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libGuiLua.so -o ' .. lib_d .. '/libGuiLua.so GuiLua.o') runCommand('C apps', dir, 'gcc ' .. CFLAGS .. ' -Wl,-export-dynamic -o ../../skang skang.c ' .. LDFLAGS .. ' -lGuiLua ' .. libs) diff --git a/src/GuiLua/skang.c b/src/GuiLua/skang.c index facc239..f78c1c5 100644 --- a/src/GuiLua/skang.c +++ b/src/GuiLua/skang.c @@ -3,11 +3,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) { - elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR); - elm_app_compile_data_dir_set(PACKAGE_DATA_DIR); - elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR); - elm_app_info_set(elm_main, "GuiLua", "skang.lua"); - + HamrTime(elm_main, "GuiLua"); GuiLuaDo(argc, argv); return 0; diff --git a/src/GuiLua/test.sh b/src/GuiLua/test.sh index bea2fc3..0cf39d9 100755 --- a/src/GuiLua/test.sh +++ b/src/GuiLua/test.sh @@ -2,5 +2,5 @@ wd=$(pwd) -export LUA_PATH="$wd/../../libraries/?.lua;./?.lua" +export LUA_PATH="$wd/../../lib/?.lua;./?.lua" ../../skang -l test -foo "argy bargy" diff --git a/src/LuaSL/LuaSL_compile.c b/src/LuaSL/LuaSL_compile.c index 771888e..f32e0c0 100644 --- a/src/LuaSL/LuaSL_compile.c +++ b/src/LuaSL/LuaSL_compile.c @@ -2119,9 +2119,9 @@ boolean compilerSetup(gameGlobals *ourGlobals) } // Compile the constants. - snprintf(buf, sizeof(buf), "lua -e 'require(\"LSL\").gimmeLSL()' > %s/libraries/constants.lsl", PACKAGE_DATA_DIR); + snprintf(buf, sizeof(buf), "lua -e 'require(\"LSL\").gimmeLSL()' > %s/constants.lsl", PACKAGE_LIB_DIR); system(buf); - snprintf(buf, sizeof(buf), "%s/libraries/constants.lsl", PACKAGE_DATA_DIR); + snprintf(buf, sizeof(buf), "%s/constants.lsl", PACKAGE_LIB_DIR); compileLSL(ourGlobals, NULL, "FAKE_SID", buf, TRUE); return TRUE; diff --git a/src/LuaSL/LuaSL_test.c b/src/LuaSL/LuaSL_test.c index 58d6225..27b9626 100644 --- a/src/LuaSL/LuaSL_test.c +++ b/src/LuaSL/LuaSL_test.c @@ -147,7 +147,7 @@ static Eina_Bool _add(void *data, int type __UNUSED__, Ecore_Con_Event_Server_Ad ourGlobals->server = ev->server; gettimeofday(&startTime, NULL); - snprintf(buf, sizeof(buf), "%s/media/Test sim/objects", PACKAGE_DATA_DIR); + snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR); eina_file_dir_list(buf, EINA_TRUE, dirList_compile, ourGlobals); // Wait awhile, then start sending events for testing. ecore_timer_add(0.5, _timer_cb, ourGlobals); @@ -392,7 +392,7 @@ int main(int argc, char **argv) evas_object_focus_set(ourGlobals.bg, EINA_TRUE); ourGlobals.edje = edje_object_add(ourGlobals.canvas); - snprintf(buf, sizeof(buf), "%s/media/%s.edj", PACKAGE_DATA_DIR, "LuaSL"); + snprintf(buf, sizeof(buf), "%s/%s.edj", PACKAGE_DATA_DIR, "LuaSL"); if (!edje_object_file_set(ourGlobals.edje, buf, group)) { int err = edje_object_load_error_get(ourGlobals.edje); @@ -409,7 +409,7 @@ int main(int argc, char **argv) evas_object_resize(ourGlobals.edje, WIDTH, HEIGHT); evas_object_show(ourGlobals.edje); - snprintf(buf, sizeof(buf), "%s/media/bubble_sh.png", PACKAGE_DATA_DIR); + snprintf(buf, sizeof(buf), "%s/bubble_sh.png", PACKAGE_DATA_DIR); for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++) { sh = evas_object_image_filled_add(ourGlobals.canvas); @@ -419,7 +419,7 @@ int main(int argc, char **argv) evas_object_data_set(ourGlobals.bg, names[(i * 2) + 1], sh); } - snprintf(buf, sizeof(buf), "%s/media/bubble.png", PACKAGE_DATA_DIR); + snprintf(buf, sizeof(buf), "%s/bubble.png", PACKAGE_DATA_DIR); for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++) { bub = evas_object_image_filled_add(ourGlobals.canvas); diff --git a/src/LuaSL/build.lua b/src/LuaSL/build.lua index f86715c..6b34145 100755 --- a/src/LuaSL/build.lua +++ b/src/LuaSL/build.lua @@ -13,11 +13,20 @@ if 'nil' == type(dir) then dir = workingDir end + removeFiles(dir, {'../../LuaSL', '*.o', '*.output', '*.backup', '../../media/LuaSL.edj', 'LuaSL_lexer.h', 'LuaSL_lexer.c', 'LuaSL_lemon_yaccer.h', 'LuaSL_lemon_yaccer.c', 'LuaSL_lemon_yaccer.out'}) -- Run lemon first, flex depends on it to define the symbol values. runCommand('lemon', dir, '../../libraries/lemon/lemon -s -T../../libraries/lemon/lempar.c LuaSL_lemon_yaccer.y') runCommand('flex', dir, 'flex -C --outfile=LuaSL_lexer.c --header-file=LuaSL_lexer.h LuaSL_lexer.l') runCommand('edje_cc', dir, 'edje_cc ' .. EDJE_FLAGS .. ' LuaSL.edc ../../media/LuaSL.edj') + +-- While SledHamr.c does this, we can't use that here, coz LuaSL is not an Elm app. +-- Neither is LuaSL_test actually. +CFLAGS = CFLAGS .. ' -DPACKAGE_BIN_DIR=\\"' .. bin_d .. '\\"' +CFLAGS = CFLAGS .. ' -DPACKAGE_LIB_DIR=\\"' .. lib_d .. '\\"' +CFLAGS = CFLAGS .. ' -DPACKAGE_DATA_DIR=\\"' .. data_d .. '\\"' +CFLAGS = CFLAGS .. ' -DPACKAGE_LOCALE_DIR=\\"' .. locale_d .. '\\"' + compileFiles('../../LuaSL', dir, {'LuaSL_main', 'LuaSL_compile', 'LuaSL_threads', 'LuaSL_utilities', 'LuaSL_lexer', 'LuaSL_lemon_yaccer'}) compileFiles('LuaSL_test', dir, {'LuaSL_test', 'LuaSL_utilities'}) diff --git a/src/LuaSL/test.sh b/src/LuaSL/test.sh index 1c26ade..435c5e2 100755 --- a/src/LuaSL/test.sh +++ b/src/LuaSL/test.sh @@ -4,7 +4,7 @@ wd=$(pwd) # Kill any left overs. killall -KILL LuaSL -export LUA_PATH="$wd/../../libraries/?.lua" +export LUA_PATH="$wd/../../lib/?.lua" case $@ in diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index 09b5196..ab09fd0 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -39,7 +39,7 @@ static Elm_Genlist_Item_Class *viewer_gic = NULL; //static const char *img1 = PACKAGE_DATA_DIR "/media/plant_01.jpg"; //static const char *img2 = PACKAGE_DATA_DIR "/media/sky_01.jpg"; -static const char *img3 = PACKAGE_DATA_DIR "/media/rock_01.jpg"; +static const char *img3 = "rock_01.jpg"; #define EPHYSICS_TEST_THEME "extantz" @@ -1240,7 +1240,7 @@ static void woMan_add(GLData *gld) // Evas_Object *win, *bg, *bx, *ic, *bb, *av, *en, *bt, *nf, *tab, *tb, *gridList, *viewerList, *menu; Evas_Object *win, *bx, *bt, *nf, *tab, *tb, *gridList, *viewerList, *menu; Elm_Object_Item *tb_it, *menu_it, *tab_it; -// char buf[PATH_MAX]; + char buf[PATH_MAX]; int i; win = fang_win_add(gld); @@ -1351,9 +1351,10 @@ static void woMan_add(GLData *gld) evas_object_size_hint_weight_set(nf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(nf, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(nf); - + + sprintf(buf, "%s/%s", elm_app_data_dir_get(), img3); tab = viewerList; tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Viewers", _promote, tab_it); - tab = _content_image_new(win, img3); tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Landmarks", _promote, tab_it); + tab = _content_image_new(win, strdup(buf)); tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Landmarks", _promote, tab_it); tab = gridList; tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Grids", _promote, tab_it); elm_box_pack_end(bx, nf); @@ -1393,7 +1394,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) EPhysics_Body *box_body1, *box_body2; Evas_Object *box1, *box2; GLData *gld = NULL; -// char buf[PATH_MAX]; + char buf[PATH_MAX]; // int i; // Eina_Bool gotWebKit = elm_need_web(); // Initialise ewebkit if it exists, or return EINA_FALSE if it don't. @@ -1401,10 +1402,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) // Don't do this, we need to clean up other stuff to, so set a clean up function below. //elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); - // If you want efl to handle finding your bin/lib/data dirs, you must do this below. - elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR); - elm_app_compile_data_dir_set(PACKAGE_DATA_DIR); - elm_app_info_set(elm_main, "datadir", "media/sky_03.jpg"); + HamrTime(elm_main, "extantz"); fprintf(stdout, "prefix was set to: %s\n", elm_app_prefix_dir_get()); fprintf(stdout, "data directory is: %s\n", elm_app_data_dir_get()); fprintf(stdout, "library directory is: %s\n", elm_app_lib_dir_get()); @@ -1538,7 +1536,8 @@ EAPI_MAIN int elm_main(int argc, char **argv) ephysics_body_friction_set(boundary, 0); box1 = elm_image_add(gld->win); - elm_image_file_set(box1, PACKAGE_DATA_DIR "/media/" EPHYSICS_TEST_THEME ".edj", "blue-cube"); + sprintf(buf, "%s/%s.edj", elm_app_data_dir_get(), EPHYSICS_TEST_THEME); + elm_image_file_set(box1, strdup(buf), "blue-cube"); evas_object_move(box1, gld->win_w / 2 - 80, gld->win_h - 200); evas_object_resize(box1, 70, 70); evas_object_show(box1); @@ -1552,7 +1551,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) ephysics_body_sleeping_threshold_set(box_body1, 0.1, 0.1); box2 = elm_image_add(gld->win); - elm_image_file_set(box2, PACKAGE_DATA_DIR "/media/" EPHYSICS_TEST_THEME ".edj", "purple-cube"); + elm_image_file_set(box2, strdup(buf), "purple-cube"); evas_object_move(box2, gld->win_w / 2 + 10, gld->win_h - 200); evas_object_resize(box2, 70, 70); evas_object_show(box2); diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h index afb94af..25b78cf 100644 --- a/src/extantz/extantz.h +++ b/src/extantz/extantz.h @@ -6,14 +6,8 @@ #define USE_DEMO 1 #define DO_GEARS 0 -#if USE_EO - /* Enable access to unstable EFL API that are still in beta */ - #define EFL_BETA_API_SUPPORT 1 - /* Enable access to unstable EFL EO API. */ - #define EFL_EO_API_SUPPORT 1 -#endif -#include +#include "SledjHamr.h" #include #include #include diff --git a/src/libraries/LumbrJack.c b/src/libraries/LumbrJack.c new file mode 100644 index 0000000..084d916 --- /dev/null +++ b/src/libraries/LumbrJack.c @@ -0,0 +1,85 @@ +/* LumbrJack - a logging library that wraps Eina logging. + +*/ + + +#include "LumbrJack.h" + + +static char dateTime[DATE_TIME_LEN]; + +static void _ggg_log_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args) +{ + FILE *f = data; + char dt[DATE_TIME_LEN + 1]; + char fileTab[256], funcTab[256]; + + getDateTime(NULL, dt, NULL); + dt[19] = '\0'; + if (12 > strlen(file)) + snprintf(fileTab, sizeof(fileTab), "%s\t\t", file); + else + snprintf(fileTab, sizeof(fileTab), "%s\t", file); + snprintf(funcTab, sizeof(funcTab), "\t%s", fnc); + fprintf(f, "%s ", dt); + if (f == stderr) + eina_log_print_cb_stderr(d, level, fileTab, funcTab, line, fmt, data, args); + else if (f == stdout) + eina_log_print_cb_stdout(d, level, fileTab, funcTab, line, fmt, data, args); + fflush(f); +} + +int loggingStartup(char *name, int logDom) +{ + if (logDom < 0) + { + logDom = eina_log_domain_register(name, NULL); + if (logDom < 0) + { + EINA_LOG_CRIT("could not register log domain '%s'", name); + return logDom; + } + } + eina_log_level_set(EINA_LOG_LEVEL_DBG); + eina_log_domain_level_set(name, EINA_LOG_LEVEL_DBG); + eina_log_print_cb_set(_ggg_log_print_cb, stderr); + + // Shut up the excess debugging shit from EFL. + eina_log_domain_level_set("eo", EINA_LOG_LEVEL_WARN); + eina_log_domain_level_set("eldbus", EINA_LOG_LEVEL_WARN); + eina_log_domain_level_set("eet", EINA_LOG_LEVEL_WARN); + eina_log_domain_level_set("ecore", EINA_LOG_LEVEL_WARN); + eina_log_domain_level_set("ecore_audio", EINA_LOG_LEVEL_WARN); + eina_log_domain_level_set("ecore_con", EINA_LOG_LEVEL_WARN); + eina_log_domain_level_set("ecore_evas", EINA_LOG_LEVEL_WARN); + eina_log_domain_level_set("ecore_input_evas", EINA_LOG_LEVEL_WARN); + eina_log_domain_level_set("ecore_input_evas", EINA_LOG_LEVEL_WARN); + eina_log_domain_level_set("ecore_system_upower", EINA_LOG_LEVEL_WARN); + eina_log_domain_level_set("eio", EINA_LOG_LEVEL_WARN); + eina_log_domain_level_set("evas_main", EINA_LOG_LEVEL_WARN); + + return logDom; +} + +char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut) +{ + struct tm *newTime; + time_t szClock; + char *date = dateTime; + + // Get time in seconds + time(&szClock); + // Convert time to struct tm form + newTime = localtime(&szClock); + + if (nowOut) + *nowOut = newTime; + if (dateOut) + date = dateOut; + if (timeOut) + *timeOut = szClock; + + // format + strftime(date, DATE_TIME_LEN, "%d/%m/%Y %H:%M:%S\r", newTime); + return (dateTime); +} diff --git a/src/libraries/LumbrJack.h b/src/libraries/LumbrJack.h new file mode 100644 index 0000000..4a3290c --- /dev/null +++ b/src/libraries/LumbrJack.h @@ -0,0 +1,38 @@ + +#include +#include + +#include + + +#define PC(...) EINA_LOG_DOM_CRIT(ourGlobals->logDom, __VA_ARGS__) +#define PE(...) EINA_LOG_DOM_ERR(ourGlobals->logDom, __VA_ARGS__) +#define PW(...) EINA_LOG_DOM_WARN(ourGlobals->logDom, __VA_ARGS__) +#define PD(...) EINA_LOG_DOM_DBG(ourGlobals->logDom, __VA_ARGS__) +#define PI(...) EINA_LOG_DOM_INFO(ourGlobals->logDom, __VA_ARGS__) + +#define PCm(...) EINA_LOG_DOM_CRIT(ourGlobals.logDom, __VA_ARGS__) +#define PEm(...) EINA_LOG_DOM_ERR(ourGlobals.logDom, __VA_ARGS__) +#define PWm(...) EINA_LOG_DOM_WARN(ourGlobals.logDom, __VA_ARGS__) +#define PDm(...) EINA_LOG_DOM_DBG(ourGlobals.logDom, __VA_ARGS__) +#define PIm(...) EINA_LOG_DOM_INFO(ourGlobals.logDom, __VA_ARGS__) + +#define D() PD("DEBUG") + + +// "01:03:52 01-01-1973\n\0" +#define DATE_TIME_LEN 21 + + +#ifndef FALSE +// NEVER change this +typedef enum +{ + FALSE = 0, + TRUE = 1 +} boolean; +#endif + + +int loggingStartup(char *name, int logDom); +char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); diff --git a/src/libraries/Runnr.c b/src/libraries/Runnr.c new file mode 100644 index 0000000..a24e7f5 --- /dev/null +++ b/src/libraries/Runnr.c @@ -0,0 +1,318 @@ +/* Runnr - a library that deals with running Lua scripts. + +*/ + + +#include "Runnr.h" + + +void dumpStack(lua_State *L, int i) +{ + int type = lua_type(L, i); + + switch (type) + { + case LUA_TNONE : printf("Stack %d is empty\n", i); break; + case LUA_TNIL : printf("Stack %d is a nil\n", i); break; + case LUA_TBOOLEAN : printf("Stack %d is a boolean - %d\n", i, lua_toboolean(L, i)); break; + case LUA_TNUMBER : printf("Stack %d is a number\n - %f", i, lua_tonumber(L, i)); break; + case LUA_TSTRING : printf("Stack %d is a string - %s\n", i, lua_tostring(L, i)); break; + case LUA_TFUNCTION : printf("Stack %d is a function\n", i); break; + case LUA_TTHREAD : printf("Stack %d is a thread\n", i); break; + case LUA_TTABLE : + { + int j; + + printf("Stack %d is a table", i); + lua_getfield(L, i, "_NAME"); + j = lua_gettop(L); + if (lua_isstring(L, j)) + printf(" - %s", lua_tostring(L, j)); + lua_pop(L, 1); + printf("\n"); + break; + } + case LUA_TUSERDATA : printf("Stack %d is a userdata\n", i); break; + case LUA_TLIGHTUSERDATA : printf("Stack %d is a light userdata\n", i); break; + default : printf("Stack %d is unknown\n", i); break; + } +} + + +// These are what the various symbols are for each type - +// int % +// num # +// str $ +// bool ! +// C func & +// table.field @ Expects an integer and a string. +// nil ~ +// table {} Starts and stops filling up a new table. +// ( Just syntax sugar for call. +// call ) Expects an integer, the number of results left after the call. +// FIXME: Still to do, if we ever use them - +// stack = Get a value from the stack, expects a stack index. +// userdata + +// lightuserdata * +// thread ^ + +static char *_push_name(lua_State *L, char *q, int *idx) // Stack usage [-0, +1, e or m] +{ + char *p = q; + char temp = '\0'; + + // A simplistic scan through an identifier, it's wrong, but it's quick, + // and we don't mind that it's wrong, coz this is only internal. + while (isalnum((int)*q)) + q++; + temp = *q; + *q = '\0'; + if (*idx > 0) + lua_getfield(L, *idx, p); // Stack usage [-0, +1, e] + else + { + if (p != q) + lua_pushstring(L, p); // Stack usage [-0, +1, m] + else + { + lua_pushnumber(L, (lua_Number) (0 - (*idx))); + (*idx)--; + } + } + *q = temp; + + return q; +} + +int pull_lua(lua_State *L, int i, char *params, ...) // Stack usage - + // if i is a table + // [-n, +n, e] + // else + // [-0, +0, -] +{ + va_list vl; + char *f = strdup(params); + char *p = f; + int n = 0, j = i, count = 0; + Eina_Bool table = EINA_FALSE; + + if (!f) return -1; + va_start(vl, params); + + if (lua_istable(L, i)) // Stack usage [-0, +0, -] + { + j = -1; + table = EINA_TRUE; + } + + while (*p) + { + char *q; + Eina_Bool get = EINA_TRUE; + + while (isspace((int)*p)) + p++; + q = p + 1; + switch (*p) + { + case '%': + { + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, e] + if (lua_isnumber(L, j)) // Stack usage [-0, +0, -] + { + int *v = va_arg(vl, int *); + *v = lua_tointeger(L, j); // Stack usage [-0, +0, -] + n++; + } + break; + } + case '#': + { + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, e] + if (lua_isnumber(L, j)) // Stack usage [-0, +0, -] + { + double *v = va_arg(vl, double *); + *v = lua_tonumber(L, j); // Stack usage [-0, +0, -] + n++; + } + break; + } + case '$': + { + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, e] + if (lua_isstring(L, j)) // Stack usage [-0, +0, -] + { + char **v = va_arg(vl, char **); + size_t len; + char *temp = (char *) lua_tolstring(L, j, &len); // Stack usage [-0, +0, m] + + len++; // Cater for the null at the end. + *v = malloc(len); + if (*v) + { + memcpy(*v, temp, len); + n++; + } + } + break; + } + case '!': + { + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, e] + if (lua_isboolean(L, j)) // Stack usage [-0, +0, -] + { + int *v = va_arg(vl, int *); + *v = lua_toboolean(L, j); // Stack usage [-0, +0, -] + n++; + } + break; + } + default: + { + get = EINA_FALSE; + break; + } + } + + if (get) + { + if (table) + { + // If this is a table, then we pushed a value on the stack, pop it off. + lua_pop(L, 1); // Stack usage [-n, +0, -] + } + else + j++; + count++; + } + p = q; + } + + va_end(vl); + free(f); + if (count > n) + n = 0; + else if (table) + n = 1; + return n; +} + +int push_lua(lua_State *L, char *params, ...) // Stack usage [-0, +n, em] +{ + va_list vl; + char *f = strdup(params); + char *p = f; + int n = 0, table = 0, i = -1; + + if (!f) return -1; + + va_start(vl, params); + + while (*p) + { + char *q; + Eina_Bool set = EINA_TRUE; + + while (isspace((int)*p)) + p++; + q = p + 1; + switch (*p) + { + case '%': + { + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, m] + lua_pushinteger(L, va_arg(vl, int)); // Stack usage [-0, +1, -] + break; + } + case '#': + { + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, m] + lua_pushnumber(L, va_arg(vl, double)); // Stack usage [-0, +1, -] + break; + } + case '$': + { + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, m] + lua_pushstring(L, va_arg(vl, char *)); // Stack usage [-0, +1, m] + break; + } + case '!': + { + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, m] + lua_pushboolean(L, va_arg(vl, int)); // Stack usage [-0, +1, -] + break; + } + case '=': + { + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, m] + lua_pushvalue(L, va_arg(vl, int)); // Stack usage [-0, +1, -] + break; + } + case '@': + { + int tabl = va_arg(vl, int); + char *field = va_arg(vl, char *); + + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, m] + lua_getfield(L, tabl, field); // Stack usage [-0, +1, e] + break; + } + case '&': + { + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, m] + lua_pushcfunction(L, va_arg(vl, void *)); // Stack usage [-0, +1, m] + break; + } + case '~': + { + if (table) q = _push_name(L, q, &i); // Stack usage [-0, +1, m] + lua_pushnil(L); // Stack usage [-0, +1, -] + break; + } + case '(': // Just syntax sugar. + { + set = EINA_FALSE; + break; + } + case ')': + { + lua_call(L, n - 1, va_arg(vl, int)); + n = 0; + set = EINA_FALSE; + break; + } + case '{': + { + lua_newtable(L); + table++; + n++; + set = EINA_FALSE; + break; + } + case '}': + { + table--; + set = EINA_FALSE; + break; + } + default: + { + set = EINA_FALSE; + break; + } + } + + if (set) + { + if (table > 0) + lua_settable(L, -3); // Stack usage [-2, +0, e] + else + n++; + } + p = q; + } + + va_end(vl); + free(f); + return n; +} diff --git a/src/libraries/Runnr.h b/src/libraries/Runnr.h new file mode 100644 index 0000000..dc720ff --- /dev/null +++ b/src/libraries/Runnr.h @@ -0,0 +1,15 @@ + +#include +#include + +#include + +#include +#include +#include +#include + + +void dumpStack(lua_State *L, int i); +int pull_lua(lua_State *L, int i, char *params, ...); +int push_lua(lua_State *L, char *params, ...); diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c new file mode 100644 index 0000000..aa68774 --- /dev/null +++ b/src/libraries/SledjHamr.c @@ -0,0 +1,23 @@ +#include "SledjHamr.h" + +void HamrTime(void *elm_main, char *domain) +{ + elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR); + elm_app_compile_data_dir_set(PACKAGE_DATA_DIR); + elm_app_compile_lib_dir_set(PACKAGE_LIB_DIR); + elm_app_compile_locale_set(PACKAGE_LOCALE_DIR); + // Do this after the above calls, but before changing the working directory, or screwing with argv[0]. + // It tries to set up the package paths depending on where the executable is, so things are relocatable. + // First argument is the elm_main() function that Elementary starts us from. + // Second argument should be a lower case string used as the "domain", which is different from the log domain. + // It's used lower case as part of the data directory path. + // So, if prefix is /usr/local, then the system data dir is /usr/local/share, + // and this apps data dir is /usr/local/share/"domain". + // It's used upper case as part of environment variables to override directory paths at run time. + // So "DOMAIN"_PREFIX, "DOMAIN"_BIN_DIR, "DOMAIN"_LIB_DIR, "DOMAIN"_DATA_DIR, and "DOMAIN"_LOCALE_DIR + // Third argument is the name of a file it can check for to make sure it found the correct path. + // This file is looked for in the data dir. + elm_app_info_set(elm_main, domain, "checkme.txt"); + // Once this is all setup, the code can do - + // elm_app_prefix_dir_get(); // or bin, lib, data, locale. +} diff --git a/src/libraries/SledjHamr.h b/src/libraries/SledjHamr.h new file mode 100644 index 0000000..893d90e --- /dev/null +++ b/src/libraries/SledjHamr.h @@ -0,0 +1,14 @@ + +#define EFL_API_OVERRIDE 1 +/* Enable access to unstable EFL API that are still in beta */ +#define EFL_BETA_API_SUPPORT 1 +/* Enable access to unstable EFL EO API. */ +#define EFL_EO_API_SUPPORT 1 + +#include +#include + +#include + + +void HamrTime(void *elm_main, char *domain); diff --git a/src/libraries/build.lua b/src/libraries/build.lua new file mode 100755 index 0000000..6566e66 --- /dev/null +++ b/src/libraries/build.lua @@ -0,0 +1,33 @@ +#!/usr/bin/env lua + +local dir = ... + +if 'nil' == type(dir) then + local build, err = loadfile('../../build.lua') + if build then + setfenv(build, getfenv(2)) + build(2) + else + print("ERROR - " .. err) + end + dir = workingDir +end + +LDFLAGS = '-L ' .. dir .. ' ' .. LDFLAGS + +removeFiles(dir, {'LumbrJack.o', lib_d .. '/libLumbrJack.so', 'Runnr.o', lib_d .. '/libRunnr.so', 'SledjHamr.o', lib_d .. '/libSledjHamr.so'}) + +runCommand('C libraries', dir, 'gcc ' .. CFLAGS .. ' -fPIC -c LumbrJack.c') +runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libLumbrJack.so -o ' .. lib_d .. '/libLumbrJack.so LumbrJack.o') + +runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -fPIC -c Runnr.c') +runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libRunnr.so -o ' .. lib_d .. '/libRunnr.so Runnr.o') + +-- For Elm apps, these are all centrally controlled in libSledjHamr. +CFLAGS = CFLAGS .. ' -DPACKAGE_BIN_DIR=\\"' .. bin_d .. '\\"' +CFLAGS = CFLAGS .. ' -DPACKAGE_LIB_DIR=\\"' .. lib_d .. '\\"' +CFLAGS = CFLAGS .. ' -DPACKAGE_DATA_DIR=\\"' .. data_d .. '\\"' +CFLAGS = CFLAGS .. ' -DPACKAGE_LOCALE_DIR=\\"' .. locale_d .. '\\"' + +runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -fPIC -c SledjHamr.c') +runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libSledjHamr.so -o ' .. lib_d .. '/libSledjHamr.so SledjHamr.o') -- cgit v1.1