comparison src/if_lua.c @ 2431:7b764999f9b9 vim73

Update for Lua interface. (Luis Carvalho)
author Bram Moolenaar <bram@vim.org>
date Wed, 28 Jul 2010 22:46:08 +0200
parents f149bb1cf5be
children 8c512e2c7cb5
comparison
equal deleted inserted replaced
2430:55b20270a4ce 2431:7b764999f9b9
107 /* libs */ 107 /* libs */
108 #define luaopen_base dll_luaopen_base 108 #define luaopen_base dll_luaopen_base
109 #define luaopen_table dll_luaopen_table 109 #define luaopen_table dll_luaopen_table
110 #define luaopen_string dll_luaopen_string 110 #define luaopen_string dll_luaopen_string
111 #define luaopen_math dll_luaopen_math 111 #define luaopen_math dll_luaopen_math
112 #define luaopen_io dll_luaopen_io
112 #define luaopen_os dll_luaopen_os 113 #define luaopen_os dll_luaopen_os
113 #define luaopen_package dll_luaopen_package 114 #define luaopen_package dll_luaopen_package
114 #define luaopen_debug dll_luaopen_debug 115 #define luaopen_debug dll_luaopen_debug
116 #define luaL_openlibs dll_luaL_openlibs
115 117
116 /* lauxlib */ 118 /* lauxlib */
117 void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l); 119 void (*dll_luaL_register) (lua_State *L, const char *libname, const luaL_Reg *l);
118 int (*dll_luaL_typerror) (lua_State *L, int narg, const char *tname); 120 int (*dll_luaL_typerror) (lua_State *L, int narg, const char *tname);
119 const char *(*dll_luaL_checklstring) (lua_State *L, int numArg, size_t *l); 121 const char *(*dll_luaL_checklstring) (lua_State *L, int numArg, size_t *l);
166 /* libs */ 168 /* libs */
167 int (*dll_luaopen_base) (lua_State *L); 169 int (*dll_luaopen_base) (lua_State *L);
168 int (*dll_luaopen_table) (lua_State *L); 170 int (*dll_luaopen_table) (lua_State *L);
169 int (*dll_luaopen_string) (lua_State *L); 171 int (*dll_luaopen_string) (lua_State *L);
170 int (*dll_luaopen_math) (lua_State *L); 172 int (*dll_luaopen_math) (lua_State *L);
173 int (*dll_luaopen_io) (lua_State *L);
171 int (*dll_luaopen_os) (lua_State *L); 174 int (*dll_luaopen_os) (lua_State *L);
172 int (*dll_luaopen_package) (lua_State *L); 175 int (*dll_luaopen_package) (lua_State *L);
173 int (*dll_luaopen_debug) (lua_State *L); 176 int (*dll_luaopen_debug) (lua_State *L);
177 void (*dll_luaL_openlibs) (lua_State *L);
174 178
175 typedef void **luaV_function; 179 typedef void **luaV_function;
176 typedef struct { 180 typedef struct {
177 const char *name; 181 const char *name;
178 luaV_function func; 182 luaV_function func;
232 /* libs */ 236 /* libs */
233 {"luaopen_base", (luaV_function) &dll_luaopen_base}, 237 {"luaopen_base", (luaV_function) &dll_luaopen_base},
234 {"luaopen_table", (luaV_function) &dll_luaopen_table}, 238 {"luaopen_table", (luaV_function) &dll_luaopen_table},
235 {"luaopen_string", (luaV_function) &dll_luaopen_string}, 239 {"luaopen_string", (luaV_function) &dll_luaopen_string},
236 {"luaopen_math", (luaV_function) &dll_luaopen_math}, 240 {"luaopen_math", (luaV_function) &dll_luaopen_math},
241 {"luaopen_io", (luaV_function) &dll_luaopen_io},
237 {"luaopen_os", (luaV_function) &dll_luaopen_os}, 242 {"luaopen_os", (luaV_function) &dll_luaopen_os},
238 {"luaopen_package", (luaV_function) &dll_luaopen_package}, 243 {"luaopen_package", (luaV_function) &dll_luaopen_package},
239 {"luaopen_debug", (luaV_function) &dll_luaopen_debug}, 244 {"luaopen_debug", (luaV_function) &dll_luaopen_debug},
245 {"luaL_openlibs", (luaV_function) &dll_luaL_openlibs},
240 {NULL, NULL} 246 {NULL, NULL}
241 }; 247 };
242 248
243 static HANDLE hinstLua = NULL; 249 static HANDLE hinstLua = NULL;
244 250
1092 1098
1093 static lua_State * 1099 static lua_State *
1094 luaV_newstate(void) 1100 luaV_newstate(void)
1095 { 1101 {
1096 lua_State *L = luaL_newstate(); 1102 lua_State *L = luaL_newstate();
1097 const luaL_Reg luaV_core_libs[] = { 1103 luaL_openlibs(L); /* core libs */
1098 {"", luaopen_base}, 1104 lua_pushcfunction(L, luaopen_vim); /* vim */
1099 {LUA_TABLIBNAME, luaopen_table},
1100 {LUA_STRLIBNAME, luaopen_string},
1101 {LUA_MATHLIBNAME, luaopen_math},
1102 {LUA_OSLIBNAME, luaopen_os}, /* restricted */
1103 {LUA_LOADLIBNAME, luaopen_package},
1104 {LUA_DBLIBNAME, luaopen_debug},
1105 {NULL, NULL}
1106 };
1107 const char *os_funcs[] = {
1108 "date", "clock", "time", "difftime", "getenv", NULL
1109 };
1110 const luaL_Reg *reg = luaV_core_libs;
1111 const char **s = os_funcs;
1112 /* core libs */
1113 for ( ; reg->func; reg++)
1114 {
1115 lua_pushcfunction(L, reg->func);
1116 lua_pushstring(L, reg->name);
1117 lua_call(L, 1, 0);
1118 }
1119 /* restricted os lib */
1120 lua_getglobal(L, LUA_OSLIBNAME);
1121 lua_newtable(L);
1122 for ( ; *s; s++)
1123 {
1124 lua_getfield(L, -2, *s);
1125 lua_setfield(L, -2, *s);
1126 }
1127 lua_setglobal(L, LUA_OSLIBNAME);
1128 lua_pop(L, 1); /* os table */
1129 /* vim */
1130 lua_pushcfunction(L, luaopen_vim);
1131 lua_call(L, 0, 0); 1105 lua_call(L, 0, 0);
1132 return L; 1106 return L;
1133 } 1107 }
1134 1108
1135 static void 1109 static void