|
Hi Bel,I somehow always had problems in the last weeks in answering in this mailing list, but now it looks like it might work.... this is what I am doing now: I use a debug hook with n=100, and then count these 100 "command hook" events... . Generally quite ok. Just I thought it possibly might be somehow nicer to give this value more exactly... ... but I will survive this +-100 command counter accuracy, this is "quite ok". Anyway I am so impressed and happy with the flawless working of Lua together with my software, and especially also the really very smart and nice error info possibilities, that I am very happy and cannot complain really about Lua... (I compare it to _javascript_ which I had used before, but it was really very bloated up and really difficult for me to implement nice error message to users in case of script errors...).On Sat, May 1, 2021 at 6:11 PM bel <bel2125@gmail.com> wrote:What about using a hook with a high count value and reading the hook count before and after your calls?On Sat, May 1, 2021 at 1:37 PM nerditation <nerditation@outlook.com> wrote:On 2021/4/14 22:47, Flyer31 Test wrote:
> Hi,
>
[...]
>
> Is it possible to readout the current value of this Lua command counter
in an easy way in C or Lua?
>
if by "command counter" you mean the number of VM instructions (or OPCODEs), the answer is no,
one obvious reason there no such API is because the VM is an "implementation detail", and as far
as I know, Lua does not keep track of it at all,
if you insist on using it, you must patch the VM and do it yourself, but I highly suggest against this idea,
and I don't think this counter would make much sense any way.
the VM OPCODEs are designed to be easily mapped to semantics of the Lua language, and easy to implement
efficiently. it is not meant to be used as performance measurement.
becase some of the OPCODEs represent very simple computations such as a single arithmetic addition,
or logical shift; while other OPCODEs might represent quite complex (thus
resource heavy) operations,
such as the generic `for` loop, or creating a closure; the counter of OPCODEs executed/interpreted
by the VM is meaningless for most users.