Translating Lua keywords

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Translating Lua keywords

Dirk Laurie-2
By editing the array of keywords `luaX_tokens` in llex.c, one can change
any of the keywords to another word (anything that would be a legal name
seems to be acceptable, but one can't for example change `and` to `&&`).

In one case it is not as easy as in the others.

"return" must be changed in the function "pushline" in lua.c too, in the
line
   lua_pushfstring(L, "return %s", b+1);  /* change it to `return' */
otherwise you can't use the "=" shortcut in the interactive interpreter.

This seems to be the only instance in the Lua source code outside the
definition of `luaX_tokens` where a keyword occurs hard-coded in a
string. The hard-coding can be avoided at the cost of making lua.c
include llex.h.

Reply | Threaded
Open this post in threaded view
|

Re: Translating Lua keywords

Roberto Ierusalimschy
> In one case it is not as easy as in the others.
>
> "return" must be changed in the function "pushline" in lua.c too, in the
> line
>    lua_pushfstring(L, "return %s", b+1);  /* change it to `return' */
> otherwise you can't use the "=" shortcut in the interactive interpreter.
>
> This seems to be the only instance in the Lua source code outside the
> definition of `luaX_tokens` where a keyword occurs hard-coded in a
> string. The hard-coding can be avoided at the cost of making lua.c
> include llex.h.

lua.c is a client of the Lua core. 'return' is hardcoded there as it
is hardcoded in any piece of Lua code.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Translating Lua keywords

Henning Diedrich
Hi Roberto,

On Apr 11, 2013, at 2:22 PM, Roberto Ierusalimschy <[hidden email]> wrote:

>
> lua.c is a client of the Lua core. 'return' is hardcoded there as it
> is hardcoded in any piece of Lua code.
>
> -- Roberto

can you restate that maybe? I don't quite get it.

Thanks,

Henning
Reply | Threaded
Open this post in threaded view
|

Re: Translating Lua keywords

Matthew Wild
On 11 April 2013 21:52, Henning Diedrich <[hidden email]> wrote:

> Hi Roberto,
>
> On Apr 11, 2013, at 2:22 PM, Roberto Ierusalimschy <[hidden email]> wrote:
>
>>
>> lua.c is a client of the Lua core. 'return' is hardcoded there as it
>> is hardcoded in any piece of Lua code.
>>
>> -- Roberto
>
> can you restate that maybe? I don't quite get it.
>

Firstly, lua.c (the standalone command-line interpreter) is just an
app that uses Lua, the library.

Secondly, the 'return' hard-coded in lua.c is just a piece of standard
Lua code. There is no reason that it should be changed without a
change to Lua, the language.

Another simpler way to put it - if Dirk were to build a version of Lua
with all the keywords translated to Lojban, all existing Lua scripts
would need to be rewritten to work with it. The 'return' in lua.c is
just another one of these scripts, except that it happens to be very
short and embedded inside a C file :)

Regards,
Matthew

Reply | Threaded
Open this post in threaded view
|

Re: Translating Lua keywords

Dirk Laurie-2
2013/4/12 Matthew Wild <[hidden email]>:

> Another simpler way to put it - if Dirk were to build a version of Lua
> with all the keywords translated to Lojban, all existing Lua scripts
> would need to be rewritten to work with it.

That's the problem. It is simple, even trivial to change `llex.c` to
accept other keywords _instead of_ the standard ones. It's harder, and
in fact I have not even tried, to accept other keywords _as aliases of_
the standard ones. That could actually be useful, whereas my symbolic
patch is just a joke (sorry, I missed the April 1 deadline).

Reply | Threaded
Open this post in threaded view
|

Re: Translating Lua keywords

Luiz Henrique de Figueiredo
> It is simple, even trivial to change `llex.c` to accept other keywords
> _instead of_ the standard ones. It's harder, and in fact I have not
> even tried, to accept other keywords _as aliases of_ the standard ones.

I haven't tried but I think adding aliases is just adding the words to
luaX_tokens and possibily repeating the enum values in enum RESERVED
in llex.h. The only drawback is that error messages will use the first
occurrence of the keyword in luaX_tokens.