Message ID | 20201111212810.825205-1-sbabic@denx.de |
---|---|
State | Accepted |
Headers | show |
Series | Cosmetic: move lua handler search path to log | expand |
Hi Stefano, > Signed-off-by: Stefano Babic <sbabic@denx.de> > --- > corelib/lua_interface.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c > index 192563b..0f1b4f5 100644 > --- a/corelib/lua_interface.c > +++ b/corelib/lua_interface.c > @@ -1114,8 +1114,20 @@ int lua_handlers_init(void) > if ((ret = luaL_dostring(gL, "require (\"swupdate_handlers\")")) != 0) { > INFO("No Lua handler(s) found."); > if (luaL_dostring(gL, "return package.path:gsub(';','\\n'):gsub('?','swupdate_handlers')") == 0) { > + TRACE("Lua handler search path:"); > lua_pop(gL, 1); > - TRACE("Lua handler search path:\n%s", lua_tostring(gL, -1)); > + char *s = strdupa(lua_tostring(gL, -1)); > + char *s1 = s; > + char *lf; > + > + do { > + lf = strchr(s1, '\n'); > + if (lf) > + *lf = '\0'; > + TRACE("\t%s", s1); > + if (lf) > + s1 = ++lf; > + } while (lf); Hm, why not make use of gsub()'s 2nd return value being the number of items returned, like the following?: if (luaL_dostring(gL, "return package.path:gsub('?','swupdate_handlers'):gsub(';','\\0')") == 0) { const char *paths = lua_tostring(gL, -2); for (int i=lua_tonumber(gL, -1); i >= 0; i--) { TRACE("\t%s", paths); paths += strlen(paths) + 1; } lua_pop(gL, 2); } Kind regards, Christian
Hi Christian, On 13.11.20 14:24, Christian Storm wrote: > Hi Stefano, > >> Signed-off-by: Stefano Babic <sbabic@denx.de> >> --- >> corelib/lua_interface.c | 14 +++++++++++++- >> 1 file changed, 13 insertions(+), 1 deletion(-) >> >> diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c >> index 192563b..0f1b4f5 100644 >> --- a/corelib/lua_interface.c >> +++ b/corelib/lua_interface.c >> @@ -1114,8 +1114,20 @@ int lua_handlers_init(void) >> if ((ret = luaL_dostring(gL, "require (\"swupdate_handlers\")")) != 0) { >> INFO("No Lua handler(s) found."); >> if (luaL_dostring(gL, "return package.path:gsub(';','\\n'):gsub('?','swupdate_handlers')") == 0) { >> + TRACE("Lua handler search path:"); >> lua_pop(gL, 1); >> - TRACE("Lua handler search path:\n%s", lua_tostring(gL, -1)); >> + char *s = strdupa(lua_tostring(gL, -1)); >> + char *s1 = s; >> + char *lf; >> + >> + do { >> + lf = strchr(s1, '\n'); >> + if (lf) >> + *lf = '\0'; >> + TRACE("\t%s", s1); >> + if (lf) >> + s1 = ++lf; >> + } while (lf); > > Hm, why not make use of gsub()'s 2nd return value being the number of > items returned, like the following?: > This is a great idea instead of doing this in code, many thanks ! > > if (luaL_dostring(gL, "return package.path:gsub('?','swupdate_handlers'):gsub(';','\\0')") == 0) { > const char *paths = lua_tostring(gL, -2); > for (int i=lua_tonumber(gL, -1); i >= 0; i--) { > TRACE("\t%s", paths); > paths += strlen(paths) + 1; > } > lua_pop(gL, 2); > } Nice ! I fix it ! Best regards, Stefano
diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 192563b..0f1b4f5 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -1114,8 +1114,20 @@ int lua_handlers_init(void) if ((ret = luaL_dostring(gL, "require (\"swupdate_handlers\")")) != 0) { INFO("No Lua handler(s) found."); if (luaL_dostring(gL, "return package.path:gsub(';','\\n'):gsub('?','swupdate_handlers')") == 0) { + TRACE("Lua handler search path:"); lua_pop(gL, 1); - TRACE("Lua handler search path:\n%s", lua_tostring(gL, -1)); + char *s = strdupa(lua_tostring(gL, -1)); + char *s1 = s; + char *lf; + + do { + lf = strchr(s1, '\n'); + if (lf) + *lf = '\0'; + TRACE("\t%s", s1); + if (lf) + s1 = ++lf; + } while (lf); lua_pop(gL, 1); } } else {
Signed-off-by: Stefano Babic <sbabic@denx.de> --- corelib/lua_interface.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)