Hi,
The Lua interface does not include all Lua core libs: it excludes the "io"
library and offers a restricted "os" library. However, since vim itself offers
system calls, this seems like an over-prudent constraint. In addition, there
has been recent interest in having all libs to the interface, especially "io".
The attached simple patch loads all Lua core libs for the interface.
Cheers,
Luis
--
Computers are useless. They can only give you answers.
-- Pablo Picasso
--
Luis Carvalho (Kozure)
lua -e 'print((("[email protected]"):gsub("(%u+%.)","")))'
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
--- src/if_lua.c.orig 2010-07-27 13:43:39.760548921 -0400
+++ src/if_lua.c 2010-07-27 16:19:00.507520217 -0400
@@ -109,9 +109,11 @@
#define luaopen_table dll_luaopen_table
#define luaopen_string dll_luaopen_string
#define luaopen_math dll_luaopen_math
+#define luaopen_io dll_luaopen_io
#define luaopen_os dll_luaopen_os
#define luaopen_package dll_luaopen_package
#define luaopen_debug dll_luaopen_debug
+#define luaL_openlibs dll_luaL_openlibs
/* lauxlib */
void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l);
@@ -168,9 +170,11 @@
int (*dll_luaopen_table) (lua_State *L);
int (*dll_luaopen_string) (lua_State *L);
int (*dll_luaopen_math) (lua_State *L);
+int (*dll_luaopen_io) (lua_State *L);
int (*dll_luaopen_os) (lua_State *L);
int (*dll_luaopen_package) (lua_State *L);
int (*dll_luaopen_debug) (lua_State *L);
+void (*dll_luaL_openlibs) (lua_State *L);
typedef void **luaV_function;
typedef struct {
@@ -234,9 +238,11 @@
{"luaopen_table", (luaV_function) &dll_luaopen_table},
{"luaopen_string", (luaV_function) &dll_luaopen_string},
{"luaopen_math", (luaV_function) &dll_luaopen_math},
+ {"luaopen_io", (luaV_function) &dll_luaopen_io},
{"luaopen_os", (luaV_function) &dll_luaopen_os},
{"luaopen_package", (luaV_function) &dll_luaopen_package},
{"luaopen_debug", (luaV_function) &dll_luaopen_debug},
+ {"luaL_openlibs", (luaV_function) &dll_luaL_openlibs},
{NULL, NULL}
};
@@ -1094,40 +1100,8 @@
luaV_newstate(void)
{
lua_State *L = luaL_newstate();
- const luaL_Reg luaV_core_libs[] = {
- {"", luaopen_base},
- {LUA_TABLIBNAME, luaopen_table},
- {LUA_STRLIBNAME, luaopen_string},
- {LUA_MATHLIBNAME, luaopen_math},
- {LUA_OSLIBNAME, luaopen_os}, /* restricted */
- {LUA_LOADLIBNAME, luaopen_package},
- {LUA_DBLIBNAME, luaopen_debug},
- {NULL, NULL}
- };
- const char *os_funcs[] = {
- "date", "clock", "time", "difftime", "getenv", NULL
- };
- const luaL_Reg *reg = luaV_core_libs;
- const char **s = os_funcs;
- /* core libs */
- for ( ; reg->func; reg++)
- {
- lua_pushcfunction(L, reg->func);
- lua_pushstring(L, reg->name);
- lua_call(L, 1, 0);
- }
- /* restricted os lib */
- lua_getglobal(L, LUA_OSLIBNAME);
- lua_newtable(L);
- for ( ; *s; s++)
- {
- lua_getfield(L, -2, *s);
- lua_setfield(L, -2, *s);
- }
- lua_setglobal(L, LUA_OSLIBNAME);
- lua_pop(L, 1); /* os table */
- /* vim */
- lua_pushcfunction(L, luaopen_vim);
+ luaL_openlibs(L); /* core libs */
+ lua_pushcfunction(L, luaopen_vim); /* vim */
lua_call(L, 0, 0);
return L;
}