lua-users home
lua-l archive

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


On Fri, Jul 28, 2017 at 10:04 AM, Coda Highland <chighland@gmail.com> wrote:
> On Fri, Jul 28, 2017 at 11:22 AM, Luiz Henrique de Figueiredo
> <lhf@tecgraf.puc-rio.br> wrote:
>>> Would you be open to considering dlopen()'ing readline? Then you
>>> wouldn't have to worry about it actually being installed, you'd just
>>> detect it at runtime and use it if it's available.
>>
>> Oh, this may open another big can of worms. For instance, which is the
>> full path of the readline.so to use in dlopen?
>>
>> However, this does not solve the problem because lua.c has to call
>> readline and cannot detect this at compiel time.
>>
>> If you could provide working code for your suggestion, I'd like to see it.
>>
>
> I don't believe you actually need to know the full path. On the two
> platforms I have available to me for testing -- Linux and OSX -- if
> you give dlopen() a path that does not contain a slash then it will
> search the system library path for the library in question. A Google
> search for the FreeBSD and Solaris man pages for dlopen() says that it
> works there, too.
>
> You would have to subsequently use dlsym() to get the functions you
> need to call instead of using header files, so it's definitely a bit
> of extra code, although you could fall back to basic stdio functions
> afterward.

Sorry about the partial emails. I don't know how I'm hitting send by accident.

I think Daunes patch provides the code you were referring to?

+#if defined(LUA_USE_READLINE)    /* { */
+  void *rdl;
+  if ((rdl = dlopen("libreadline.so",RTLD_LAZY|RTLD_LOCAL))
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpedantic"
+      && (readline = dlsym(rdl,"readline"))
+      && (add_history = dlsym(rdl,"add_history"))) {
+#pragma clang diagnostic pop
+    freeline = free;
+  } else {
+    fprintf(stderr,"Readline Disabled [%s]\n",dlerror());
+    readline = _readline;
+    add_history = _add_history;
+    freeline = _freeline;
+  }
+#endif

Russ

> I don't have time to write code at the present moment, but I'll see if
> I can get back to you on that.
>
> /s/ Adam