| 508 | #include <dlfcn.h> |
| 509 | |
| 510 | static void lua_initreadline (lua_State *L) { |
| 511 | void *lib = dlopen(LUA_READLINELIB, RTLD_NOW | RTLD_LOCAL); |
| 512 | if (lib == NULL) |
| 513 | lua_warning(L, "library '" LUA_READLINELIB "' not found", 0); |
| 514 | else { |
| 515 | const char **name = cast(const char**, dlsym(lib, "rl_readline_name")); |
| 516 | if (name != NULL) |
| 517 | *name = "lua"; |
| 518 | l_readline = cast(l_readlineT, cast_func(dlsym(lib, "readline"))); |
| 519 | l_addhist = cast(l_addhistT, cast_func(dlsym(lib, "add_history"))); |
| 520 | if (l_readline == NULL) |
| 521 | lua_warning(L, "unable to load 'readline'", 0); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | #else /* }{ */ |
| 526 | /* no dlopen or LUA_READLINELIB undefined */ |