Hi list,
Two questions:
1) Is there a standard header that I can put in my e-mails that means
"this is _NOT GOING to be used in production code UNDER ANY
CIRCUMSTANCES_, this is going to be a personal hack that I will
only load into a Lua interpreter BY HAND for some VERY CONTROLLED
tests, etc, etc"?
(Can you please suppose that I started my e-mail with a header like
this? I've been considering asking the question below here at the
list for YEARS, but EVERY SINGLE TIME I predicted the probable
reaction of the professional programmers in the list and gave
up...)
By the way, I am the author of the article "Bootstrapping a Forth
in 40 lines of Lua code" that appeared in the Lua Gems book. One of
its last paragraphs is this:
I've met many people over the years who have been Forth
enthusiasts in the past, and we often end up discussing what made
Forth so thrilling to use at that time - and what we can do to
adapt its ideas to the computers of today. My personal impression
is that Forth's main points were not the ones that I listed at
the beginning of this section, and that I said that were easy to
quantify; rather, what was most important was that nothing was
hidden, there were no complex data structures around with
"don't-look-at-this" parts (think on garbage collection in Lua,
for example, and Lua's tables - beginners need to be convinced to
see these things abstractly, as the concrete details of the
implementation are hard), and _everything_ - code, data,
dictionaries, stacks - were just linear sequences of bytes, that
could be read and modified directly if we wished to. We had total
freedom, defining new words was quick, and experiments were quick
to make; that gave us a sense of power that was totally different
from, say, the one that a Python user feels today because he has
huge libraries at his fingertips.
The technical question that I want to ask is related to using Lua
as Forths were used in the early 90's - there were LOTS of commands
that if used wrongly could freeze the system and require a reboot,
and we were perfectly happy with that.
2) Here is the idea; the question is below.
The functions debug.getinfo, debug.getlocal and debug.setlocal are
usually called with an integer argument that the manual refers to
as "level", that is processed like this (I took the code from
db_getinfo, in ldblib.c) to set the variable "ar" to an "activation
record":
if (lua_isnumber(L, arg+1)) {
if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
lua_pushnil(L); /* level out of range */
return 1;
}
}
I would like to have _variants_ of these functions, to be called
debug.mygetinfo, debug.mygetlocal and debug.mysetlocal, that would
accept an alternative to a numerical "level". Running
ar = debug.mygetstack(2)
would set ar to a string like
"activation record: 0x125cf20"
whose address part points to the "activation record" of a function
in the call stack, like the pointer that
lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)
puts into ar, and if we are super-ultra-careful then we can call
debug.mygetinfo, debug.mygetlocal and debug.mysetlocal in either of
these ways, the second one being equivalent to the first one:
debug.mygetinfo (2, "n")
debug.mygetinfo (ar, "n")
debug.mygetlocal(2, 3)
debug.mygetlocal(ar, 3)
debug.mysetlocal(2, 3, 42)
debug.mysetlocal(ar, 3, 42)
But OF COURSE if we set ar to a bad address, say,
ar = "activation record: 0x12345678"
then debug.mygetinfo, debug.mygetlocal and debug.mysetlocal WOULD
NOT HESITATE to use that address and segfault (HAHAHA! DEAL WITH
THIS, MODERN PROGRAMMERS!!!)...
The question is: has anyone implemented something like this, or
something that would cover a part of this? I haven't written any C
code in ages... I think I can implement it myself, alone, but that
would take me one or two full days just for a prototype in which I
would just change ldblib.c... putting these new functions into a
".so" would take more.
Thanks in advance!!!
Eduardo Ochs =)