lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On 17/02/17 03:53 PM, Roberto Ierusalimschy wrote:
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

Wouldn't that affect `arg`? Or is `arg` created before any argument processing takes place?

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.