From e4e750b9a749899f1eaa3b666381c39e9dc4bd7b Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 9 Apr 2014 13:41:38 +1000 Subject: Make GuiLua an actual shared library, plus some minor clean ups. --- ClientHamr/GuiLua/GuiLua.c | 89 ++++----------------------------------- ClientHamr/GuiLua/GuiLua.h | 70 ++++++++++++++++++++++++++++++ ClientHamr/GuiLua/build.sh | 12 ++++-- ClientHamr/GuiLua/skang.c | 11 +++++ ClientHamr/GuiLua/skang.lua | 12 +++--- ClientHamr/GuiLua/test.lua | 1 + ClientHamr/GuiLua/test.properties | 2 +- ClientHamr/GuiLua/test.sh | 3 ++ ClientHamr/GuiLua/test_c.c | 9 ---- 9 files changed, 108 insertions(+), 101 deletions(-) create mode 100644 ClientHamr/GuiLua/GuiLua.h create mode 100644 ClientHamr/GuiLua/skang.c create mode 100755 ClientHamr/GuiLua/test.sh (limited to 'ClientHamr') diff --git a/ClientHamr/GuiLua/GuiLua.c b/ClientHamr/GuiLua/GuiLua.c index 47b46ca..47f63d5 100644 --- a/ClientHamr/GuiLua/GuiLua.c +++ b/ClientHamr/GuiLua/GuiLua.c @@ -2,10 +2,8 @@ Provides the skang and widget Lua packages. -This should be a library in the end, but for now it's just an -application that is a test bed for what goes into the library. In the -initial intended use case, several applications will be using this all at -once, with one central app hosting all the GUIs. +In the initial intended use case, several applications will be using +this all at once, with one central app hosting all the GUIs. Basically this should deal with "windows" and their contents. A "window" in this case is hosted in the central app as some sort of @@ -43,10 +41,7 @@ Lua scripts do - Seems simplest. Also - - Most of what is in here becomes a library for dynamic linking to C code. - Pretty much just leaving main(), though most of what is in there right now should become another function. Some of this gets shared with LuaSL, since it came from there anyway. - Perhaps GuiLua.so will work, and I don't have to think of another name. lol Finally - Add a --gui command line option, that runs foo.skang. @@ -144,68 +139,15 @@ and ordinary elementary widgets. Proper introspection can come later. -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -typedef struct _globals globals; - - -#define WIDTH (300) -#define HEIGHT (300) - -#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 - -struct _globals -{ - Ecore_Evas *ee; // Our window. - Evas *canvas; // The canvas for drawing directly onto. - Evas_Object *bg; // Our background edje. - lua_State *L; // Our Lua state. - int eina, logDom, ecore_evas, edje; -}; - - globals ourGlobals; +#include "GuiLua.h" +globals ourGlobals; static const char *ourName = "widget"; -int skang, _M; +static int skang, _M; + -/* -static void dumpStack(lua_State *L, int i) +void dumpStack(lua_State *L, int i) { int type = lua_type(L, i); @@ -224,15 +166,8 @@ static void dumpStack(lua_State *L, int i) default : printf("Stack %d is unknown\n", i); break; } } -*/ - - -char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); - -# define DATE_TIME_LEN 21 - -char dateTime[DATE_TIME_LEN]; +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) { @@ -307,13 +242,11 @@ char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut) } - static void _on_delete(Ecore_Evas *ee /*__UNUSED__*/) { ecore_main_loop_quit(); } - static int openWindow(lua_State *L) { globals *ourGlobals; @@ -487,10 +420,8 @@ int luaopen_widget(lua_State *L) return 1; } - -int main(int argc, char **argv) +void GuiLuaDo(int argc, char **argv) { - int result = EXIT_FAILURE; lua_Number i; memset(&ourGlobals, 0, sizeof(globals)); @@ -532,6 +463,4 @@ int main(int argc, char **argv) } else fprintf(stderr, "Failed to start Lua!\n"); - - return result; } diff --git a/ClientHamr/GuiLua/GuiLua.h b/ClientHamr/GuiLua/GuiLua.h new file mode 100644 index 0000000..1813966 --- /dev/null +++ b/ClientHamr/GuiLua/GuiLua.h @@ -0,0 +1,70 @@ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +typedef struct _globals globals; + + +#define WIDTH (300) +#define HEIGHT (300) + +#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 + +struct _globals +{ + Ecore_Evas *ee; // Our window. + Evas *canvas; // The canvas for drawing directly onto. + Evas_Object *bg; // Our background edje. + lua_State *L; // Our Lua state. + int eina, logDom, ecore_evas, edje; +}; + +// globals ourGlobals; + + +void dumpStack(lua_State *L, int i); + + +# define DATE_TIME_LEN 21 + +//char dateTime[DATE_TIME_LEN]; + +void loggingStartup(globals *ourGlobals); +char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); + +int luaopen_widget(lua_State *L); +void GuiLuaDo(int argc, char **argv); diff --git a/ClientHamr/GuiLua/build.sh b/ClientHamr/GuiLua/build.sh index 5c111e4..0ef46b9 100755 --- a/ClientHamr/GuiLua/build.sh +++ b/ClientHamr/GuiLua/build.sh @@ -12,7 +12,7 @@ else export E17DIR="/usr" fi -CFLAGS="-g -Wall -Wunreachable-code -I include -I $LOCALDIR" +CFLAGS="-g -Wall -I include -I $LOCALDIR" CFLAGS="$CFLAGS -I ../../libraries" #CFLAGS="$CFLAGS -I ../../libraries/LuaJIT-2.0.2/src" CFLAGS="$CFLAGS $(pkg-config --cflags luajit)" @@ -34,7 +34,7 @@ CFLAGS="$CFLAGS -DPACKAGE_DATA_DIR=\"$LOCALDIR\" $CFLAGOPTS" #LDFLAGS="-L ../../libraries/LuaJIT-2.0.2/src -L lib -L /usr/lib -L /lib -L $E17DIR/lib" #libs="-leo -lecore -levas -ledje -lembryo -leet -leina -lluajit -lpthread -lm" -LDFLAGS="$(pkg-config --libs-only-L luajit) -L lib -L /usr/lib -L /lib -L $E17DIR/lib" +LDFLAGS="-L $LOCALDIR $(pkg-config --libs-only-L luajit) -L lib -L /usr/lib -L /lib -L $E17DIR/lib" libs="-leo -lecore -levas -ledje -lembryo -leet -leina $(pkg-config --libs luajit) -lpthread -lm -ldl" #LDFLAGS="-L /usr/lib/lua/5.1 -L lib -L /usr/lib -L /lib -L $E17DIR/lib" #libs="-lecore -levas -ledje -lembryo -leet -leina -llua5.1 -lpthread -lm" @@ -49,7 +49,11 @@ libs="-leo -lecore -levas -ledje -lembryo -leet -leina $(pkg-config --libs luaji #-lz echo "clean" -rm -f test_c.so test_c.o +rm -f test_c.so GuiLua.o libGuiLua.so skang echo "C modules" gcc $CFLAGS -fPIC -shared -o test_c.so test_c.c -gcc $CFLAGS -o GuiLua GuiLua.c $LDFLAGS $libs +gcc $CFLAGS -fPIC -c GuiLua.c +echo "C libraries" +gcc $CFLAGS -shared -Wl,-soname,libGuiLua.so -o libGuiLua.so GuiLua.o +echo "C apps" +gcc $CFLAGS -Wl,-export-dynamic -o skang skang.c $LDFLAGS -lGuiLua $libs diff --git a/ClientHamr/GuiLua/skang.c b/ClientHamr/GuiLua/skang.c new file mode 100644 index 0000000..ed92ff9 --- /dev/null +++ b/ClientHamr/GuiLua/skang.c @@ -0,0 +1,11 @@ +#include "GuiLua.h" + + +int main(int argc, char **argv) +{ + int result = EXIT_FAILURE; + + GuiLuaDo(argc, argv); + + return result; +} diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index e738a50..dec8983 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua @@ -1,7 +1,7 @@ --[[ TODO - This should be in C, but so far development has been quite rapid doing it in Lua. + C will let us - Actually do the widget stuff. - Use Ecore's main loop. Slap meta tables on all value types. Which lets us put the meta table on the variable, instead of on the table, which I think is cleaner. Figure out the directory separator. @@ -907,6 +907,9 @@ copy = function (parent, name) return result end +module = function (name) + return require(name) +end stuff = function (aThingy, aStuff) return getmetatable(aThingy).__self.stuff[aStuff] @@ -954,11 +957,11 @@ set = function (stuff, key, name, value) end end +thingasm('module,l', 'Load a module.', module, 'file') thingasm('get', 'Get the current value of an existing Thing or metadata.', get, 'thing,key,name') thingasm('reset', 'Reset the current value of an existing Thing or metadata.', reset, 'thing,key,name') thingasm('set', 'Set the current value of an existing Thing or metadata.', set, 'thing,key,name,data') - thingasm('nada', 'Do nothing.', function () --[[ This function intentionally left blank. ]] end) @@ -968,10 +971,6 @@ end window = function (width, height, title) end -module = function (name) - return require(name) -end - skang = function (name) end quit = function () @@ -979,7 +978,6 @@ end thingasm('clear', 'The current skin is cleared of all widgets.', clear) thingasm{'window', 'The size and title of the application Frame.', window, 'x,y,name', acl='GGG'} -thingasm('module,l', 'Load a module.', module, 'file') thingasm('skang', 'Parse the contents of a skang file or URL.', skang, 'URL') thingasm('quit', 'Quit, exit, remove thyself.', quit) diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua index f45aff9..d484cf2 100644 --- a/ClientHamr/GuiLua/test.lua +++ b/ClientHamr/GuiLua/test.lua @@ -46,6 +46,7 @@ print(test.DEFAULT_SKANG) print('') print('foo = ' .. test.foo .. ' ->> ' .. skang.get(test, 'foo', 'help')) +print('fooble = ' .. test.fooble) print('cfooble = ' .. test_c.cfooble .. ' ->> ' .. skang.get(test_c, 'cfooble', 'help') .. '[' .. skang.get(test_c, 'cfooble', 'widget') .. ']') print('cfunc ->> ' .. skang.get(test_c, 'cfunc', 'help')) test.ffunc('one', 2) diff --git a/ClientHamr/GuiLua/test.properties b/ClientHamr/GuiLua/test.properties index d6d29cb..71a371d 100644 --- a/ClientHamr/GuiLua/test.properties +++ b/ClientHamr/GuiLua/test.properties @@ -1 +1 @@ -foo = 'forty two' +fooble = 'forty two' diff --git a/ClientHamr/GuiLua/test.sh b/ClientHamr/GuiLua/test.sh new file mode 100755 index 0000000..4f72c52 --- /dev/null +++ b/ClientHamr/GuiLua/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +export LD_LIBRARY_PATH="."; ./skang -l test -foo "argy bargy" diff --git a/ClientHamr/GuiLua/test_c.c b/ClientHamr/GuiLua/test_c.c index e4ca278..6faf928 100644 --- a/ClientHamr/GuiLua/test_c.c +++ b/ClientHamr/GuiLua/test_c.c @@ -1,14 +1,5 @@ /* Should be a Lua skang module, roughly the same as test.lua -TODO - See if this still works if it's an app instead of a library. - I think the problem will be duplicate Lua library names. - The C app will be linked to one copy, the lua executable that require() this is linked to another, even if it's the same one. - Much hilarity ensues. - Not to mention linker flags being different. - - Plan B - - Widget skang module runs the window app, and sends stuff to it. - Seems to be several problems with linking in various OSes, here's some possibly helpful links - -- cgit v1.1