diff options
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | ClientHamr/GuiLua/build.sh | 54 | ||||
-rw-r--r-- | ClientHamr/GuiLua/test.lua | 4 | ||||
-rw-r--r-- | ClientHamr/GuiLua/test_c.c | 113 | ||||
-rwxr-xr-x | build.sh | 4 |
5 files changed, 119 insertions, 57 deletions
@@ -310,6 +310,7 @@ | |||
310 | *.backup | 310 | *.backup |
311 | *.edj | 311 | *.edj |
312 | *.o | 312 | *.o |
313 | *.so | ||
313 | *.out | 314 | *.out |
314 | *.output | 315 | *.output |
315 | *.diff | 316 | *.diff |
diff --git a/ClientHamr/GuiLua/build.sh b/ClientHamr/GuiLua/build.sh new file mode 100755 index 0000000..387b193 --- /dev/null +++ b/ClientHamr/GuiLua/build.sh | |||
@@ -0,0 +1,54 @@ | |||
1 | #! /bin/bash | ||
2 | |||
3 | export LOCALDIR=`pwd` | ||
4 | |||
5 | # No need for a make file, or dependencies, the entire thing takes only a few seconds to build. | ||
6 | |||
7 | # This assumes you have EFL installed in one of two standard places. | ||
8 | if [ -d "/opt/EFL" ] | ||
9 | then | ||
10 | export E17DIR="/opt/EFL" | ||
11 | else | ||
12 | export E17DIR="/usr" | ||
13 | fi | ||
14 | |||
15 | CFLAGS="-g -Wall -Wunreachable-code -I include -I $LOCALDIR" | ||
16 | CFLAGS="$CFLAGS -I ../../libraries" | ||
17 | #CFLAGS="$CFLAGS -I ../../libraries/LuaJIT-2.0.2/src" | ||
18 | CFLAGS="$CFLAGS $(pkg-config --cflags luajit)" | ||
19 | #CFLAGS="$CFLAGS -I /usr/include/lua5.1" | ||
20 | CFLAGS="$CFLAGS -I $E17DIR/include/eo-1" | ||
21 | CFLAGS="$CFLAGS -I $E17DIR/include/eina-1" | ||
22 | CFLAGS="$CFLAGS -I $E17DIR/include/eina-1/eina" | ||
23 | CFLAGS="$CFLAGS -I $E17DIR/include/eet-1" | ||
24 | CFLAGS="$CFLAGS -I $E17DIR/include/embryo-1" | ||
25 | CFLAGS="$CFLAGS -I $E17DIR/include/edje-1" | ||
26 | CFLAGS="$CFLAGS -I $E17DIR/include/evas-1" | ||
27 | CFLAGS="$CFLAGS -I $E17DIR/include/ecore-1" | ||
28 | CFLAGS="$CFLAGS -I $E17DIR/include/efl-1" | ||
29 | CFLAGS="$CFLAGS -I $E17DIR/include/ecore-con-1" | ||
30 | CFLAGS="$CFLAGS -I $E17DIR/include/ecore-evas-1" | ||
31 | CFLAGS="$CFLAGS -I $E17DIR/include/ecore-file-1" | ||
32 | CFLAGS="$CFLAGS -I $E17DIR/include" | ||
33 | CFLAGS="$CFLAGS -DPACKAGE_DATA_DIR=\"$LOCALDIR\" $CFLAGOPTS" | ||
34 | |||
35 | #LDFLAGS="-L ../../libraries/LuaJIT-2.0.2/src -L lib -L /usr/lib -L /lib -L $E17DIR/lib" | ||
36 | #libs="-leo -lecore -levas -ledje -lembryo -leet -leina -lluajit -lpthread -lm" | ||
37 | LDFLAGS="$(pkg-config --libs-only-L luajit) -L lib -L /usr/lib -L /lib -L $E17DIR/lib" | ||
38 | libs="-leo -lecore -levas -ledje -lembryo -leet -leina $(pkg-config --libs-only-L luajit) -lpthread -lm" | ||
39 | #LDFLAGS="-L /usr/lib/lua/5.1 -L lib -L /usr/lib -L /lib -L $E17DIR/lib" | ||
40 | #libs="-lecore -levas -ledje -lembryo -leet -leina -llua5.1 -lpthread -lm" | ||
41 | # These need to be added to libs if linking staticaly, though some parts of EFL don't like that. | ||
42 | #-lecore_evas \ | ||
43 | #-lecore_file \ | ||
44 | #-ldl \ | ||
45 | #-lfontconfig \ | ||
46 | #-lfreetype \ | ||
47 | #-lexpat \ | ||
48 | #-lrt \ | ||
49 | #-lz | ||
50 | |||
51 | echo "clean" | ||
52 | rm -f test_c.so test_c.o | ||
53 | echo "C modules" | ||
54 | gcc $CFLAGS -fPIC -shared -o test_c.so test_c.c | ||
diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua index 58f8d19..b1ab691 100644 --- a/ClientHamr/GuiLua/test.lua +++ b/ClientHamr/GuiLua/test.lua | |||
@@ -35,7 +35,7 @@ skang.thing('foo') | |||
35 | 35 | ||
36 | -- We can use inline functions if we don't need the function internally. | 36 | -- We can use inline functions if we don't need the function internally. |
37 | skang.thing('ffunc', 'Help Text', function (arg1, arg2) | 37 | skang.thing('ffunc', 'Help Text', function (arg1, arg2) |
38 | print('Inside test.ffunc ' .. arg1 .. ', ' .. arg2) | 38 | print('Inside test.ffunc(' .. arg1 .. ', ' .. arg2 .. ')') |
39 | end, 'number,string') | 39 | end, 'number,string') |
40 | 40 | ||
41 | print('Ending soon') | 41 | print('Ending soon') |
@@ -47,12 +47,14 @@ end | |||
47 | -- Test it. | 47 | -- Test it. |
48 | local skang = require 'skang' | 48 | local skang = require 'skang' |
49 | local test = require 'test' | 49 | local test = require 'test' |
50 | local test_c = require 'test_c' | ||
50 | 51 | ||
51 | print('MODULE ' .. test._NAME .. ', ' .. test.COPYRIGHT .. ' Version: ' .. test.VERSION .. '\n' .. test.VERSION_DESC .. '\n') | 52 | print('MODULE ' .. test._NAME .. ', ' .. test.COPYRIGHT .. ' Version: ' .. test.VERSION .. '\n' .. test.VERSION_DESC .. '\n') |
52 | 53 | ||
53 | print('foo = ' .. test.foo .. ' ->> ' .. skang.things.foo.help) | 54 | print('foo = ' .. test.foo .. ' ->> ' .. skang.things.foo.help) |
54 | print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.things.ffunc.help .. ' ->> ' .. skang.things.f.action) | 55 | print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.things.ffunc.help .. ' ->> ' .. skang.things.f.action) |
55 | test.ffunc('one', 2) | 56 | test.ffunc('one', 2) |
57 | test_c.ffunc(0, 'zero') | ||
56 | --skang.things.ffunc('seven', 'aight') | 58 | --skang.things.ffunc('seven', 'aight') |
57 | print('') | 59 | print('') |
58 | 60 | ||
diff --git a/ClientHamr/GuiLua/test_c.c b/ClientHamr/GuiLua/test_c.c index 8c3796d..e7ee388 100644 --- a/ClientHamr/GuiLua/test_c.c +++ b/ClientHamr/GuiLua/test_c.c | |||
@@ -1,78 +1,79 @@ | |||
1 | /* Should be a Lua module, roughly the same as test.lua | 1 | /* Should be a Lua skang module, roughly the same as test.lua |
2 | 2 | ||
3 | */ | 3 | */ |
4 | 4 | ||
5 | 5 | ||
6 | #include <lua.h> | ||
7 | #include <lauxlib.h> | ||
8 | //#include <lualib.h> | ||
6 | 9 | ||
7 | /* NOTES - | ||
8 | 10 | ||
9 | From http://www.inf.puc-rio.br/~roberto/pil2/chapter15.pdf | 11 | static int ffunc (lua_State *L) |
12 | { | ||
13 | double arg1 = luaL_checknumber(L, 1); | ||
14 | const char *arg2 = luaL_checkstring(L, 2); | ||
10 | 15 | ||
11 | "Well-behaved C libraries should export one function called | 16 | printf("Inside test_c.ffunc(%f, %s)\n", arg1, arg2); |
12 | luaopen_modname, which is the function that require tries to call after | 17 | return 0; |
13 | linking the library. In Section 26.2 we will discuss how to write C | 18 | } |
14 | libraries." | ||
15 | 19 | ||
16 | The "modname" bit is replaced by the name of the module. Though if the | ||
17 | module name includes a hyphen, the "require" function strips out the | ||
18 | hyphen and the bit before it. | ||
19 | 20 | ||
20 | Though it seems that chapter 26 is not in the same place? | 21 | static const struct luaL_reg test_c [] = |
22 | { | ||
23 | {"ffunc", ffunc}, | ||
24 | {NULL, NULL} | ||
25 | }; | ||
21 | 26 | ||
22 | http://www.lua.org/pil/26.2.html doesn't say much really, and is for | ||
23 | Lua 5.0 | ||
24 | 27 | ||
28 | /* local test_c = require 'test_c' | ||
25 | 29 | ||
30 | Lua's require() function will strip any stuff from the front of the name | ||
31 | separated by a hypen, so 'GuiLua-test_c' -> 'test_c'. Then it will | ||
32 | search through a path, and eventually find this test_c.so (or test_c.dll | ||
33 | or whatever), then call luaopen_test_c(), which should return a table. | ||
26 | 34 | ||
27 | An example - | 35 | Normally luaL_register() creates a table of functions, that is the table |
36 | returned, but we want to do something different with skang. | ||
28 | 37 | ||
29 | // build@ gcc -shared -I/home/sdonovan/lua/include -o mylib.so mylib.c | 38 | */ |
30 | // includes for your code | 39 | int luaopen_test_c(lua_State *L) |
31 | #include <string.h> | 40 | { |
32 | #include <math.h> | 41 | // This is a moving target, old ways get deperecated, new ways get added, |
42 | // would have to check version before doing any of these. | ||
43 | // luaL_openlib(L, "test_c", test_c, 0); // Lua 5.0 way. | ||
44 | // luaL_register (L, "test_c", test_c); // Lua 5.1 way. | ||
45 | // luaL_newlib() or luaL_setfuncs() // Lua 5.2 way. | ||
46 | // Creates a global table "test_c", does the package.loaded[test_c] thing. | ||
47 | lua_newtable(L); | ||
48 | luaL_register (L, NULL, test_c); // Lua 5.1 way. | ||
49 | // Puts the funcions in a table on top of the stack. | ||
33 | 50 | ||
34 | // includes for Lua | 51 | /* BUT REALLY ... |
35 | #include <lua.h> | ||
36 | #include <lauxlib.h> | ||
37 | #include <lualib.h> | ||
38 | 52 | ||
39 | // defining functions callable from Lua | 53 | We are in fact NOT putting any functions into the returned table. |
40 | static int l_createtable (lua_State *L) { | ||
41 | int narr = luaL_optint(L,1,0); // initial array slots, default 0 | ||
42 | int nrec = luaL_optint(L,2,0); // intialof hash slots, default 0 | ||
43 | lua_createtable(L,narr,nrec); | ||
44 | return 1; | ||
45 | } | ||
46 | 54 | ||
47 | static int l_solve (lua_State *L) { | 55 | skang.moduleBegin() returns the table we need to send back to Lua. |
48 | double a = lua_tonumber(L,1); // coeff of x*x | 56 | it saves getfenv(2) as the old environment, which should in theory be L |
49 | double b = lua_tonumber(L,2); // coef of x | 57 | and setfenv(_M, 2) to set the tbale to be it's own environment |
50 | double c = lua_tonumber(L,3); // constant | 58 | it does the package.loaded[test_c] thing for us |
51 | double abc = b*b - 4*a*c; | 59 | it returns the table it created, so we should just leave that on the stack as our result |
52 | if (abc < 0.0) { | ||
53 | lua_pushnil(L); | ||
54 | lua_pushstring(L,"imaginary roots!"); | ||
55 | return 2; | ||
56 | } else { | ||
57 | abc = sqrt(abc); | ||
58 | a = 2*a; | ||
59 | lua_pushnumber(L,(-b + abc)/a); | ||
60 | lua_pushnumber(L,(+b - abc)/a); | ||
61 | return 2; | ||
62 | } | ||
63 | } | ||
64 | 60 | ||
65 | static const luaL_reg mylib[] = { | 61 | skang.thing() also uses getfenv(2) to grab the module's table |
66 | {"createtable",l_createtable}, | ||
67 | {"solve",l_solve}, | ||
68 | {NULL,NULL} | ||
69 | }; | ||
70 | 62 | ||
71 | int luaopen_mylib(lua_State *L) | 63 | */ |
72 | { | ||
73 | luaL_register (L, "mylib", mylib); | ||
74 | return 1; | ||
75 | } | ||
76 | 64 | ||
65 | /* TODO - load skang, create things, etc. | ||
66 | |||
67 | local skang = require "skang" | ||
68 | local _M = skang.moduleBegin("test_c", nil, "Copyright 2014 David Seikel", "0.1", "2014-03-27 03:57:00") | ||
69 | |||
70 | skang.thing("fooble,f", "Help text goes here", 1, "number", "'edit', 'The fooble:', 1, 1, 10, 50", true) | ||
71 | skang.thing("bar", "Help text", "Default") | ||
72 | skang.thing("foo") | ||
73 | skang.thing("ffunc", "Help Text", ffunc, "number,string") | ||
74 | |||
75 | skang.moduleEnd(_M) | ||
77 | 76 | ||
78 | */ | 77 | */ |
78 | return 1; | ||
79 | } | ||
@@ -31,6 +31,10 @@ echo "_______________ BUILDING LuaSL _______________" | |||
31 | cd $wd/LuaSL | 31 | cd $wd/LuaSL |
32 | ./build.sh | 32 | ./build.sh |
33 | 33 | ||
34 | echo "_______________ BUILDING GuiLua _______________" | ||
35 | cd $wd/ClientHamr/GuiLua | ||
36 | ./build.sh | ||
37 | |||
34 | echo "_______________ BUILDING extantz _______________" | 38 | echo "_______________ BUILDING extantz _______________" |
35 | cd $wd/ClientHamr/extantz | 39 | cd $wd/ClientHamr/extantz |
36 | ./build.sh | 40 | ./build.sh |