[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [FEATURE REQUEST] Custom-naming of preloaded modules
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 17 Feb 2017 15:53:54 -0200
> My present version is:
>
> static int dolibrary (lua_State *L, const char *name) {
> int status;
> char *eq = strchr(name,'=');
> lua_getglobal(L, "require");
> if (eq) lua_pushstring(L, eq+1);
> else lua_pushstring(L, name);
> status = docall(L, 1, 1); /* call 'require(name)' */
> if (status == LUA_OK) {
> if (eq) *eq = 0;
> lua_setglobal(L, name); /* global[name] = require return */
> if (eq) *eq = '=';
> }
> return report(L, status);
> }
>
> Luiz has neither approved nor rejected the temporary modification of
> a character inside a "const char*", but the compiler is happy :-)
You should remove the 'const' here, but otherwise the assignment is
correct; ANSI C assures that the strings pointed to by 'argv' are
modifiable (and you don't need to restore its value).
-- Roberto