aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rwxr-xr-xClientHamr/GuiLua/build.sh54
-rw-r--r--ClientHamr/GuiLua/test.lua4
-rw-r--r--ClientHamr/GuiLua/test_c.c113
-rwxr-xr-xbuild.sh4
5 files changed, 119 insertions, 57 deletions
diff --git a/.gitignore b/.gitignore
index 3f2582a..45bc49a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
3export 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.
8if [ -d "/opt/EFL" ]
9then
10 export E17DIR="/opt/EFL"
11else
12 export E17DIR="/usr"
13fi
14
15CFLAGS="-g -Wall -Wunreachable-code -I include -I $LOCALDIR"
16CFLAGS="$CFLAGS -I ../../libraries"
17#CFLAGS="$CFLAGS -I ../../libraries/LuaJIT-2.0.2/src"
18CFLAGS="$CFLAGS $(pkg-config --cflags luajit)"
19#CFLAGS="$CFLAGS -I /usr/include/lua5.1"
20CFLAGS="$CFLAGS -I $E17DIR/include/eo-1"
21CFLAGS="$CFLAGS -I $E17DIR/include/eina-1"
22CFLAGS="$CFLAGS -I $E17DIR/include/eina-1/eina"
23CFLAGS="$CFLAGS -I $E17DIR/include/eet-1"
24CFLAGS="$CFLAGS -I $E17DIR/include/embryo-1"
25CFLAGS="$CFLAGS -I $E17DIR/include/edje-1"
26CFLAGS="$CFLAGS -I $E17DIR/include/evas-1"
27CFLAGS="$CFLAGS -I $E17DIR/include/ecore-1"
28CFLAGS="$CFLAGS -I $E17DIR/include/efl-1"
29CFLAGS="$CFLAGS -I $E17DIR/include/ecore-con-1"
30CFLAGS="$CFLAGS -I $E17DIR/include/ecore-evas-1"
31CFLAGS="$CFLAGS -I $E17DIR/include/ecore-file-1"
32CFLAGS="$CFLAGS -I $E17DIR/include"
33CFLAGS="$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"
37LDFLAGS="$(pkg-config --libs-only-L luajit) -L lib -L /usr/lib -L /lib -L $E17DIR/lib"
38libs="-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
51echo "clean"
52rm -f test_c.so test_c.o
53echo "C modules"
54gcc $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.
37skang.thing('ffunc', 'Help Text', function (arg1, arg2) 37skang.thing('ffunc', 'Help Text', function (arg1, arg2)
38 print('Inside test.ffunc ' .. arg1 .. ', ' .. arg2) 38 print('Inside test.ffunc(' .. arg1 .. ', ' .. arg2 .. ')')
39end, 'number,string') 39end, 'number,string')
40 40
41print('Ending soon') 41print('Ending soon')
@@ -47,12 +47,14 @@ end
47-- Test it. 47-- Test it.
48local skang = require 'skang' 48local skang = require 'skang'
49local test = require 'test' 49local test = require 'test'
50local test_c = require 'test_c'
50 51
51print('MODULE ' .. test._NAME .. ', ' .. test.COPYRIGHT .. ' Version: ' .. test.VERSION .. '\n' .. test.VERSION_DESC .. '\n') 52print('MODULE ' .. test._NAME .. ', ' .. test.COPYRIGHT .. ' Version: ' .. test.VERSION .. '\n' .. test.VERSION_DESC .. '\n')
52 53
53print('foo = ' .. test.foo .. ' ->> ' .. skang.things.foo.help) 54print('foo = ' .. test.foo .. ' ->> ' .. skang.things.foo.help)
54print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.things.ffunc.help .. ' ->> ' .. skang.things.f.action) 55print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.things.ffunc.help .. ' ->> ' .. skang.things.f.action)
55test.ffunc('one', 2) 56test.ffunc('one', 2)
57test_c.ffunc(0, 'zero')
56--skang.things.ffunc('seven', 'aight') 58--skang.things.ffunc('seven', 'aight')
57print('') 59print('')
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
9From http://www.inf.puc-rio.br/~roberto/pil2/chapter15.pdf 11static 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);
12luaopen_modname, which is the function that require tries to call after 17 return 0;
13linking the library. In Section 26.2 we will discuss how to write C 18}
14libraries."
15 19
16The "modname" bit is replaced by the name of the module. Though if the
17module name includes a hyphen, the "require" function strips out the
18hyphen and the bit before it.
19 20
20Though it seems that chapter 26 is not in the same place? 21static const struct luaL_reg test_c [] =
22{
23 {"ffunc", ffunc},
24 {NULL, NULL}
25};
21 26
22http://www.lua.org/pil/26.2.html doesn't say much really, and is for
23Lua 5.0
24 27
28/* local test_c = require 'test_c'
25 29
30Lua's require() function will strip any stuff from the front of the name
31separated by a hypen, so 'GuiLua-test_c' -> 'test_c'. Then it will
32search through a path, and eventually find this test_c.so (or test_c.dll
33or whatever), then call luaopen_test_c(), which should return a table.
26 34
27An example - 35Normally luaL_register() creates a table of functions, that is the table
36returned, 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 39int 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 53We are in fact NOT putting any functions into the returned table.
40static 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
47static int l_solve (lua_State *L) { 55skang.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
65static const luaL_reg mylib[] = { 61skang.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
71int 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
67local skang = require "skang"
68local _M = skang.moduleBegin("test_c", nil, "Copyright 2014 David Seikel", "0.1", "2014-03-27 03:57:00")
69
70skang.thing("fooble,f", "Help text goes here", 1, "number", "'edit', 'The fooble:', 1, 1, 10, 50", true)
71skang.thing("bar", "Help text", "Default")
72skang.thing("foo")
73skang.thing("ffunc", "Help Text", ffunc, "number,string")
74
75skang.moduleEnd(_M)
77 76
78*/ 77*/
78 return 1;
79}
diff --git a/build.sh b/build.sh
index 4231ada..28c03f7 100755
--- a/build.sh
+++ b/build.sh
@@ -31,6 +31,10 @@ echo "_______________ BUILDING LuaSL _______________"
31cd $wd/LuaSL 31cd $wd/LuaSL
32./build.sh 32./build.sh
33 33
34echo "_______________ BUILDING GuiLua _______________"
35cd $wd/ClientHamr/GuiLua
36./build.sh
37
34echo "_______________ BUILDING extantz _______________" 38echo "_______________ BUILDING extantz _______________"
35cd $wd/ClientHamr/extantz 39cd $wd/ClientHamr/extantz
36./build.sh 40./build.sh