[gegl] configure: prefer luajit for its ffi



commit f2c8282ee1d1200c6e6bb2f4ccedade4892de03b
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu Feb 7 18:00:22 2019 +0100

    configure: prefer luajit for its ffi
    
    We might even want to only look for luajit.

 bin/Makefile.am |  6 ++++++
 bin/ui.c        | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac    | 16 +++++++++++-----
 3 files changed, 72 insertions(+), 5 deletions(-)
---
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 0cbe2f704..3fd1ba9bb 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -32,6 +32,12 @@ AM_LDFLAGS =  \
        $(DEP_LIBS) $(BABL_LIBS) $(PNG_LIBS) $(LIBSPIRO) $(MATH_LIB) \
         $(MRG_LIBS) $(GEXIV2_LIBS)
 
+if HAVE_LUA
+AM_LDFLAGS += $(LUA_LIBS)
+AM_CFLAGS  += $(LUA_CFLAGS)
+endif
+
+
 bin_PROGRAMS = gegl
 
 BUILT_SOURCES=argvs-commands.inc
diff --git a/bin/ui.c b/bin/ui.c
index bbcd1eff6..67e3fa4d2 100644
--- a/bin/ui.c
+++ b/bin/ui.c
@@ -90,6 +90,13 @@ const char *css =
 
 void mrg_gegl_dirty (void);
 
+#ifdef HAVE_LUA
+
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+
+#endif
 
 #include <ctype.h>
 #include <string.h>
@@ -110,6 +117,8 @@ void mrg_gegl_dirty (void);
 #include "mrg-gegl.h"
 #include "argvs.h"
 
+
+
 /* gets the node which is the direct consumer, and not a clone.
  *
  * valid after update_ui_consumers_list (State *o, GeglNode *iter)
@@ -307,6 +316,9 @@ struct _State {
   double         prev_ms;
 
   GHashTable    *ui_consumer;
+#ifdef HAVE_LUA
+  lua_State     *L;
+#endif
 };
 
 static gboolean text_editor_active (State *o)
@@ -320,6 +332,12 @@ static State *global_state = NULL;  // XXX: for now we  rely on
                                     //      refactoring this away would be nice, but
                                     //      not a problem to have in a lua port of the same
 
+State *app_state(void);
+State *app_state(void)
+{
+  return global_state;
+}
+
 typedef struct Setting {
   char *name;
   char *description;
@@ -744,6 +762,12 @@ static void init_state (State *o)
     renderer = GEGL_RENDERER_IDLE;
 
   o->gegl = gegl_node_new ();
+
+#ifdef HAVE_LUA
+  //o->L = luaL_newstate ();
+  //luaL_openlibs(o->L);
+#endif
+
 }
 
 static void cleanup_state (State *o)
@@ -5350,6 +5374,32 @@ static void gegl_ui (Mrg *mrg, void *data)
   cairo_restore (mrg_cr (mrg));
   cairo_new_path (mrg_cr (mrg));
 
+#ifdef HAVE_LUA
+  {
+    static void *mycdata = NULL;
+    int status, result;
+    o->L = luaL_newstate ();
+    luaL_openlibs(o->L);
+
+    lua_pushlightuserdata(o->L, &mycdata);
+    lua_setglobal(o->L, "__TEMP_USERDATA__");
+
+    status = luaL_loadfile(o->L, "hello.lua");
+    if (status)
+    {
+      fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(o->L, -1));
+    }
+    else
+    {
+      result = lua_pcall(o->L, 0, LUA_MULTRET, 0);
+      if (result){
+        fprintf (stderr, "lua exec problem %s\n", lua_tostring(o->L, -1));
+      }
+    }
+    lua_close(o->L);
+  }
+#endif
+
 
   mrg_add_binding (mrg, "control-q", NULL, NULL, run_command, "quit");
   mrg_add_binding (mrg, "F11", NULL, NULL,       run_command, "toggle fullscreen");
@@ -7403,4 +7453,9 @@ cmd_todo (COMMAND_ARGS)
 }
 
 
+void cdataToPointer(void *cdata, void **pointer);
+void cdataToPointer(void *cdata, void **pointer) {
+    *pointer = cdata;
+}
+
 #endif
diff --git a/configure.ac b/configure.ac
index 56b540159..77a5fc9b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1026,12 +1026,18 @@ AC_ARG_WITH(lua, [  --without-lua           build without Lua support])
 
 have_lua="no"
 if test "x$with_lua" != "xno"; then
-PKG_CHECK_MODULES(LUA, lua >= lua_required_version,
-  have_lua="yes",
+PKG_CHECK_MODULES(LUA, luajit >= 2.0.4,
+  have_lua="yes"
+  AC_DEFINE(HAVE_LUA, 1, [Define to 1 if lua is available])
+  ,
   [PKG_CHECK_MODULES(LUA, lua5.1 >= lua_required_version,
-     have_lua="yes",
-     [PKG_CHECK_MODULES(LUA, luajit >= 2.0.4,
-      have_lua="yes",
+     have_lua="yes"
+     AC_DEFINE(HAVE_LUA, 1, [Define to 1 if lua is available])
+     ,
+     [PKG_CHECK_MODULES(LUA, lua >= lua_required_version,
+      have_lua="yes"
+      AC_DEFINE(HAVE_LUA, 1, [Define to 1 if lua is available])
+      ,
       have_lua="no  (usable lua not found)")])])
 fi
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]