lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Are you really sure that this is good idea?

I am quite new to Lua, but I think at least for beginners, it is nice
and reasonable that Lua skips all these "typical C abbreviations" ++,
--, +=, -=, *=, ...  . Too many operators I think are not helpful,
especially not for a skript language which should be "learnt easily".

But I still did not see from your proposal, why you would use /- or /+
instead of -= or += ... doesn't this writing /- or /+ really look a
bit VERY strange?

... but changing all such Lua source files I think would be very
challenging ... if you would try this you should be a complete Lua
source code expert I think. (Also please consider, that if you modify
so many files by yourself, you very easily will run into problems with
every new Lua version update..).

On Tue, Jan 18, 2022 at 12:48 PM Patrick Kurth <p.kurth@posteo.de> wrote:
>
> Hello List,
>
> at which places do I have to modify code to add new operators?
> I quite often need a // b and a // b + 1 so i thought about adding /+
> and /-, where /- is like // (only added for symmetry). I'm not sure if
> I think this is a good idea, but it seemed easy enough to try out.
>
> Well, obviously you have to add a new token, the parser has to omit the
> right operation, the opcode has to exit, the virtual machine has to be
> edited and the code generator has to be updated. That means changes in
>
> lcode.c
> llex.c
> lobject.c
> lopcodes.*
> lopnames.h
> lparser.c
> lstrlib.c -- duh
> ltm.h
> lua.h
> lvm.c
>
> Ok, that's more than I expected, anything else to look for? The
> required changes seem simple enough.
>
> And one more question: the 'K' suffix in opcodes denotes constant
> operands, but at what point does a // 2 becomes OP_IDIVK? The lexer
> only emits TK_IDIV.
>
> Kind regards,
> Patrick