{"comment":{"url":"https://api.github.com/repos/gnois/luajit-lang-toolkit/comments/12806899","html_url":"https://github.com/gnois/luajit-lang-toolkit/commit/3c0817e09d7caca816c2773eb522a300d9429535#commitcomment-12806899","id":12806899,"user":{"login":"franko","id":433545,"avatar_url":"https://avatars.githubusercontent.com/u/433545?v=3","gravatar_id":"","url":"https://api.github.com/users/franko","html_url":"https://github.com/franko","followers_url":"https://api.github.com/users/franko/followers","following_url":"https://api.github.com/users/franko/following{/other_user}","gists_url":"https://api.github.com/users/franko/gists{/gist_id}","starred_url":"https://api.github.com/users/franko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/franko/subscriptions","organizations_url":"https://api.github.com/users/franko/orgs","repos_url":"https://api.github.com/users/franko/repos","events_url":"https://api.github.com/users/franko/events{/privacy}","received_events_url":"https://api.github.com/users/franko/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":"","commit_id":"3c0817e09d7caca816c2773eb522a300d9429535","created_at":"2015-08-20T13:14:43Z","updated_at":"2015-08-20T13:14:43Z","body":"Hi Wi,\r\n\r\nseems to be a good solution. I'm just afraid for the performance aspect because you are calling \"gsub\" many times, one time for each escape character. As this is going to be done for every string literal I think it can really slow down a lot the code generation.\r\n\r\nI suggest to keep the \"escape\" function you made but to replace it with a function that use format \"%q\" and just replace in the replacing string the eventual offending newlines with:\r\n\r\nstring.gsub(<output of format \"%q\">, \"\\\\\\n\", \"\\\\n\")\r\n\r\nIn this way we keep use \"%q\" to perform the bulk of the work. This seems to be better in term of performance since the format function is written in C."}}