473,785 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lua: further investigation and comparisons with Python and Forth

Since I've seen some Forth expertise/interest in evidence here, so I'll
permit myself some observations on Lua/Python/Forth.

Lua's scripting command syntax is pretty simple, though different from
Python's. It is reference- and not variable-oriented (that is, "variables"
are merely holders for references, not values) and smacks of Python in this
regard. Functions are first-class objects; again, very similar to Python.

The big differences (for me) are two:

1) Lua is designed to be driven "from the outside" by an embedding host
program and needs to be extended via C to fulfill its stated purpose of
providing an embeddable, extendable scripting language, so the Lua C API is
much more important to me as a Lua programmer than the Python API has been
to me as a Python programmer.

2) The Lua API is stack-based, so your C extension code pushes, pops and
otherwise manipulates values on the Lua stack. These values aren't simple
processor scalars; you can push a table onto the stack, whose elements can
be tables containing tables and so on and so forth. Speaking of forth, the
Lua C API has very much the flavor of Forth on steroids. You play the same
kind of stack games, but the command prompt on the other side of Lua can be
used like an object-oriented scripting language.

One very cool aspect of Lua is that the entire state of a "Lua virtual
machine" is encapsulated in the "Lua state" data structure. This means no
hidden global variable sharing at the C language level, so you can easily
instantiate a new Lua "session" to handle each concurrent incoming socket
session in a server if you wish, and keep them all perfectly separate. To
me, that means that I can extend Lua with the appropriate C routines and
then script socket sessions in an object-oriented fashion without leaving
the comfort of my C compiler (old habits die hard). While this would be a
useless tour de force on the PC or Unix, it's actually very useful on my old
Tandem K100 4-CPU fault-tolerant system. The file system has only one level
of directory per disk volume (ack!) and so a port of Python or Java would
only be an exercise in masochism. Later Tandems sport a POSIX personality
(called OSS, or Open Systems Services), but my K100 dates from an earlier
time when mainframes still roamed the earth. Flattening the Lua source tree
to fit on the K100 wasn't too hard, and there isn't anything in Lua's
operation that requires directory nesting in the filesystem.

Aside:

It was kind of fun to draw on my previous experience with Forth in grokking
the Lua C API. For a real blast from the past, check out the Open Firmware
initiative, which has adopted Forth as the language of it's BIOS code
loader. In the future, you may be able to buy some hardware, talk to a
little Forth kernel in ROM somewhere, decide how to load a real machine
BIOS, and then set it going prior to the actual OS boot.

Before reading about Open Firmware, I had assumed that Forth had completely
dropped out of sight. Anyone else aware of counterexamples ?


Jul 18 '05 #1
4 2052
"John Benson" <js******@benso nsystems.com> writes:
Before reading about Open Firmware, I had assumed that Forth had completely
dropped out of sight. Anyone else aware of counterexamples ?


There's still a very active comp.lang.forth newsgroup filled with
dedicated Forth users.
Jul 18 '05 #2
> Before reading about Open Firmware, I had assumed that Forth had completely
dropped out of sight. Anyone else aware of counterexamples ?


$ uname -a
FreeBSD 4.9-STABLE FreeBSD 4.9-STABLE #1: Sat Dec 27 11:23:38 EST 2003
$ cd /usr/src
$ find . -name "*forth*"
../share/examples/bootforth
../sys/boot/common/interp_forth.c
../sys/boot/forth

Jul 18 '05 #3
|Thus Spake John Benson On the now historical date of Thu, 08 Jan 2004
19:54:12 -0800|
Before reading about Open Firmware, I had assumed that Forth had
completely dropped out of sight. Anyone else aware of counterexamples ?


I know that Sun systems have a forth based boot system.

Sam Walters.

--
Never forget the halloween documents.
http://www.opensource.org/halloween/
""" Where will Microsoft try to drag you today?
Do you really want to go there?"""

Jul 18 '05 #4
At some point, "John Benson" <js******@benso nsystems.com> wrote:
In the future, you may be able to buy some hardware, talk to a
little Forth kernel in ROM somewhere, decide how to load a real machine
BIOS, and then set it going prior to the actual OS boot.


Time machine strikes again! I bought one of those last year. All
recent Apple machines do this.

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)phy sics(dot)mcmast er(dot)ca
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1586
by: A.M. Kuchling | last post by:
python.org has a page of "Python vs. X" language comparisons at <http://www.python.org/doc/Comparisons.html>. They're all pretty outdated, and often unfair because they're written by a person who knows Python well but has only a nodding acquaintance with language X. I'm planning to drop this page from python.org because it's so outdated and no one is around to maintain it. If anyone wants to grab the contents and turn them into a Wiki...
0
1243
by: John Benson | last post by:
Hi, I checked out Lua as much out of curiosity about its Brazilian background as for any other reason. It seems to be a project centered in the PUC (Pontifical Catholic University of Rio de Janeiro). Since Brazil produced Antônio Carlos Jobim, I figured I better check out Lua. After checking out www.lua.org and searching for comparisons with Python, the most informative document I ran across was this: ...
4
1763
by: John Benson | last post by:
Hi, I've been experimenting with Lua on my Tandem Himalaya K100 system (a decade-old 4-CPU fault-tolerant server from Tandem/Compaq/HP) because it looked like it was simpler to port than Python. Since I've only got 128 MB per CPU and the system is already loaded with SQL and transaction processing monitor software, it's small footprint was also very attractive. Anyway that's how I got interested in Lua. There has already been some...
5
3728
by: John Benson | last post by:
Regarding the message appended below: I was in a similar situation, only I had 4 "small" (RAM-wise) legacy processors in a fault-tolerant Tandem K100 system. The system came with an old Borland C++ compiler but I didn't want to become an expert in anachronistic C++ trivia, so I ported Lua (www.lua.org) using the perfectly serviceable C compiler. Although I still need to put in library extensions to access the Tandem's Guardian OS API, Lua...
8
4123
by: Paddy McCarthy | last post by:
I just re-read "Why Python?" at http://www.linuxjournal.com/article.php?sid=3882 The article is from 2000 and shows how a programmer who programmed in many programming languages, and who wrote compilers and interpreters, was introduced to Python and came to like it. I wondered if there are any more recent interviews/articles from ESR on his scripting language tools. I would be interested to know if he still usesPython? Did he try any...
38
4812
by: BORT | last post by:
Please forgive me if this is TOO newbie-ish. I am toying with the idea of teaching my ten year old a little about programming. I started my search with something like "best FREE programming language for kids." After MUCH clicking and high-level scanning, I am looking at Python and Forth. Both have advocates that say each is a great approach to learning computers. My programming classes were a long, long time ago in a land far, far...
1
1684
by: Casey Hawthorne | last post by:
Is the only way to connect Python and Lua through a C interface? -- Regards, Casey
0
2346
by: Anders B | last post by:
Hello, Im working on a program thats reading a LUA script file with a bunch of arrays and then gets some of the information out of it to my .NET app.. And its all working great as long as I know the exact name of each key to get the value in the arrays. I would like to figure out how I can 'browse' a lua table so that I can see what it contains since sometimes the keys are dynamic and I don't know exacly what the entry name is.
0
1437
by: MimiMi | last post by:
Hi! I'm trying to learn Lua scripting from within C and I'm now stuck on this (simple?) problem. I want to pass a value from C to Lua, and then get a value from Lua back to C. Here's an example of a piece of C-code which gets a value from Lua and which works fine for me: int test_Lua() { lua_State *L=lua_open(); char myArg = "result = \"Lua-string\""; luaL_dostring(L,myArg); lua_pushstring(L,"result");
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.