From ebbfaf9602a624e1c8eb39e88661fadc56996c4b Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 24 May 2017 14:18:59 +1000 Subject: src/lapi.js: Sync lua_pushliteral implementation with lua_pushstring --- src/lapi.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lapi.js b/src/lapi.js index 0cad44a..9b10d94 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -272,16 +272,17 @@ const lua_pushfstring = function (L, fmt, ...argp) { return lobject.luaO_pushvfstring(L, fmt, argp); }; +/* Similar to lua_pushstring, but takes a JS string */ const lua_pushliteral = function (L, s) { assert(typeof s === "string" || s === undefined || s === null, "lua_pushliteral expects a JS string"); if (s === undefined || s === null) L.stack[L.top] = new TValue(CT.LUA_TNIL, null); else { - let ts = new TValue(CT.LUA_TLNGSTR, lstring.luaS_newliteral(L, s)); - L.stack[L.top] = ts; + let ts = lstring.luaS_newliteral(L, s); + lobject.setsvalue2s(L, L.top, ts); + s = ts.getstr(); /* internal copy */ } - L.top++; assert(L.top <= L.ci.top, "stack overflow"); -- cgit v1.2.3-54-g00ecf