diff options
-rw-r--r-- | loadlib.c | 9 | ||||
-rw-r--r-- | lua.c | 12 | ||||
-rw-r--r-- | luaconf.h | 9 | ||||
-rw-r--r-- | testes/main.lua | 7 |
4 files changed, 26 insertions, 11 deletions
@@ -25,15 +25,6 @@ | |||
25 | 25 | ||
26 | 26 | ||
27 | /* | 27 | /* |
28 | ** LUA_IGMARK is a mark to ignore all before it when building the | ||
29 | ** luaopen_ function name. | ||
30 | */ | ||
31 | #if !defined (LUA_IGMARK) | ||
32 | #define LUA_IGMARK "-" | ||
33 | #endif | ||
34 | |||
35 | |||
36 | /* | ||
37 | ** LUA_CSUBSEP is the character that replaces dots in submodule names | 28 | ** LUA_CSUBSEP is the character that replaces dots in submodule names |
38 | ** when searching for a C loader. | 29 | ** when searching for a C loader. |
39 | ** LUA_LSUBSEP is the character that replaces dots in submodule names | 30 | ** LUA_LSUBSEP is the character that replaces dots in submodule names |
@@ -210,12 +210,17 @@ static int dostring (lua_State *L, const char *s, const char *name) { | |||
210 | 210 | ||
211 | /* | 211 | /* |
212 | ** Receives 'globname[=modname]' and runs 'globname = require(modname)'. | 212 | ** Receives 'globname[=modname]' and runs 'globname = require(modname)'. |
213 | ** If there is no explicit modname and globname contains a '-', cut | ||
214 | ** the sufix after '-' (the "version") to make the global name. | ||
213 | */ | 215 | */ |
214 | static int dolibrary (lua_State *L, char *globname) { | 216 | static int dolibrary (lua_State *L, char *globname) { |
215 | int status; | 217 | int status; |
218 | char *suffix = NULL; | ||
216 | char *modname = strchr(globname, '='); | 219 | char *modname = strchr(globname, '='); |
217 | if (modname == NULL) /* no explicit name? */ | 220 | if (modname == NULL) { /* no explicit name? */ |
218 | modname = globname; /* module name is equal to global name */ | 221 | modname = globname; /* module name is equal to global name */ |
222 | suffix = strchr(modname, *LUA_IGMARK); /* look for a suffix mark */ | ||
223 | } | ||
219 | else { | 224 | else { |
220 | *modname = '\0'; /* global name ends here */ | 225 | *modname = '\0'; /* global name ends here */ |
221 | modname++; /* module name starts after the '=' */ | 226 | modname++; /* module name starts after the '=' */ |
@@ -223,8 +228,11 @@ static int dolibrary (lua_State *L, char *globname) { | |||
223 | lua_getglobal(L, "require"); | 228 | lua_getglobal(L, "require"); |
224 | lua_pushstring(L, modname); | 229 | lua_pushstring(L, modname); |
225 | status = docall(L, 1, 1); /* call 'require(modname)' */ | 230 | status = docall(L, 1, 1); /* call 'require(modname)' */ |
226 | if (status == LUA_OK) | 231 | if (status == LUA_OK) { |
232 | if (suffix != NULL) /* is there a suffix mark? */ | ||
233 | *suffix = '\0'; /* remove sufix from global name */ | ||
227 | lua_setglobal(L, globname); /* globname = require(modname) */ | 234 | lua_setglobal(L, globname); /* globname = require(modname) */ |
235 | } | ||
228 | return report(L, status); | 236 | return report(L, status); |
229 | } | 237 | } |
230 | 238 | ||
@@ -257,6 +257,15 @@ | |||
257 | 257 | ||
258 | #endif | 258 | #endif |
259 | 259 | ||
260 | |||
261 | /* | ||
262 | ** LUA_IGMARK is a mark to ignore all after it when building the | ||
263 | ** module name (e.g., used to build the luaopen_ function name). | ||
264 | ** Typically, the sufix after the mark is the module version, | ||
265 | ** as in "mod-v1.2.so". | ||
266 | */ | ||
267 | #define LUA_IGMARK "-" | ||
268 | |||
260 | /* }================================================================== */ | 269 | /* }================================================================== */ |
261 | 270 | ||
262 | 271 | ||
diff --git a/testes/main.lua b/testes/main.lua index 3fa94e97..11b14b44 100644 --- a/testes/main.lua +++ b/testes/main.lua | |||
@@ -225,6 +225,13 @@ prepfile("print(str.upper'alo alo', m.max(10, 20))") | |||
225 | RUN("lua -l 'str=string' '-lm=math' -e 'print(m.sin(0))' %s > %s", prog, out) | 225 | RUN("lua -l 'str=string' '-lm=math' -e 'print(m.sin(0))' %s > %s", prog, out) |
226 | checkout("0.0\nALO ALO\t20\n") | 226 | checkout("0.0\nALO ALO\t20\n") |
227 | 227 | ||
228 | |||
229 | -- test module names with version sufix ("libs/lib2-v2") | ||
230 | RUN("env LUA_CPATH='./libs/?.so' lua -l lib2-v2 -e 'print(lib2.id())' > %s", | ||
231 | out) | ||
232 | checkout("true\n") | ||
233 | |||
234 | |||
228 | -- test 'arg' table | 235 | -- test 'arg' table |
229 | local a = [[ | 236 | local a = [[ |
230 | assert(#arg == 3 and arg[1] == 'a' and | 237 | assert(#arg == 3 and arg[1] == 'a' and |