[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: What makes Lua special?
- From: Nagaev Boris <bnagaev@...>
- Date: Fri, 21 Apr 2017 11:24:51 +0100
On Fri, Apr 21, 2017 at 8:04 AM, Eike Decker <firstname.lastname@example.org> wrote:
> Do you have anything else that comes to your mind? I would also greatly
> appreciate input regarding other languages that implement these things above
> knowledgeable in C++ and PHP. While reflection works in these languages
> (somehow), it's often requires very arcane knowledge to do similar things as
> mentioned 1-3.
Take a look at Go language. It has many features you mentioned. It is
a statically typed language but it is much more convenient than C or
C++. As for me, it is somewhere in-between Lua and C. With Go I don't
have to write modules in C because Go itself is fast enough and has
enough access to low level stuff. At the same time I don't have to
embed a script language in a program for writing business logic - the
language itself is convenient enough to do that (e.g. it has GC and
rich reflection so I can for instance enumerate fields of a
structure). Finally the whole project can be written in a single
> 1) The debug API which enables me to inspect the stack variables and
> defining hook functions within my program. While this can somehow be done in
> other languages, I am not aware of any language where this is an intrinsic
> part of the language API itself; It's always a mere VM functionality that is
> "chiseled in stone".
> Also cool is the ability to set a hook function that gets executed only
> after a certain amount of instructions, which is great for programming
> contests where the most efficient solution is searched - at least this makes
> the comparison very fair.
Go provides stack information: https://golang.org/pkg/runtime and
You can also print stacks of all running goroutines (that is how
coroutines are called in Go).
There are also http://golang.org/pkg/runtime/pprof/ and
https://golang.org/pkg/runtime/trace/ packages which are very useful
to find bottlenecks in a program.
> 3) Coroutines: True coroutines are available in some other languages and
> some languages offer extensions for this, but again, this isn't easy nor
> cheap to do - and often not possible as well.
Go provides goroutines. Lua coroutines all run in a single OS thread,
but Go schedules goroutines automatically on up to GOMAXPROCS OS
threads. Lua coroutines have only one "channel" of commutation with
the rest of the world (through arguments of yield and resume), but
goroutines can have any number of channels to exchange variables.
On Fri, Apr 21, 2017 at 9:17 AM, Oliver Kroth <email@example.com> wrote:
> - multiple vale assignment, and especiall the fact that functions may return
> multiple values like
> a,b = b,a
> angle, radius = toPolar( x,y )
> - closures are great for, e.g. scheduling actions, as parameter for pattern
> substitution, iterators, etc.
> once I got the concept, I don't want to miss them again.
Go provides these two features as well.
As a bonus it has brilliant build tools which infer all the
information from Go files themselves, so you don't have to write
rockspecs, CMakeLists.txt etc. Other thing I really like is that the
package system is decentralized: import paths look like
"github.com/user/repo". There is no thing like a luarocks server for
publishing packages: you just push your code somewhere (e.g. Github or
your homepage) and other people can import it directly from there.