Note that there are some explanatory texts on larger screens.

plurals
  1. POLua = operator as print
    text
    copied!<p>In Lua, using the = operator without an l-value seems to be equivalent to a print(r-value), here are a few examples run in the Lua standalone interpreter:</p> <pre><code>&gt; = a nil &gt; a = 8 &gt; = a 8 &gt; = 'hello' hello &gt; = print function: 003657C8 </code></pre> <p>And so on...</p> <p>My question is : where can I find a detailed description of this use for the = operator? How does it work? Is it by implying a special default l-value? I guess the root of my problem is that I have no clue what to type in Google to find info about it :-)</p> <p><strong>edit</strong>:</p> <p>Thanks for the answers, you are right it's a feature of the interpreter. Silly question, for I don't know which reason I completely overlooked the obvious. I should avoid posting before the morning coffee :-) For completeness, here is the code dealing with this in the interpreter:</p> <pre><code>while ((status = loadline(L)) != -1) { if (status == 0) status = docall(L, 0, 0); report(L, status); if (status == 0 &amp;&amp; lua_gettop(L) &gt; 0) { /* any result to print? */ lua_getglobal(L, "print"); lua_insert(L, 1); if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) l_message(progname, lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)", lua_tostring(L, -1))); } } </code></pre> <p><strong>edit2</strong>:</p> <p>To be really complete, the whole trick about pushing values on the stack is in the "pushline" function:</p> <pre><code>if (firstline &amp;&amp; b[0] == '=') /* first line starts with `=' ? */ lua_pushfstring(L, "return %s", b+1); /* change it to `return' */ </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload