diff --git a/index.js b/index.js index 2bea34c..ec71e0b 100644 --- a/index.js +++ b/index.js @@ -116,6 +116,14 @@ function toLua(obj, currDepth, CurrEntry) { } if (!lodash.isObject(obj)) { if (typeof obj === 'string') { + let hasTwo = obj.indexOf("\"") >= 0; + let hasOne = obj.indexOf("\'") >= 0; + if (hasTwo && hasOne) { + return '"' + obj.replace(/\"/g, "\\\"").replace(/\'/, "\\\'") + '"'; + } + else if (hasTwo) { + return "'" + obj + "'"; + } return '"' + obj + '"'; } return obj.toString(); diff --git a/index.ts b/index.ts index f7ae08f..df940e5 100644 --- a/index.ts +++ b/index.ts @@ -112,6 +112,13 @@ function toLua(obj: any, currDepth: number, CurrEntry?: string): string { } if (!lodash.isObject(obj)) { if (typeof obj === 'string') { + let hasTwo = obj.indexOf("\"") >= 0; + let hasOne = obj.indexOf("\'") >= 0; + if (hasTwo && hasOne) { + return '"' + obj.replace(/\"/g, "\\\"").replace(/\'/, "\\\'") + '"'; + } else if (hasTwo) { + return "'" + obj + "'"; + } return '"' + obj + '"'; } return obj.toString();