delorie.com/archives/browse.cgi | search |
X-Authentication-Warning: | delorie.com: mail set sender to geda-user-bounces using -f |
X-Recipient: | geda-user AT delorie DOT com |
DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; |
d=gmail.com; s=20120113; | |
h=mime-version:date:message-id:subject:from:to:content-type; | |
bh=niU2TYGlBv7ahmVZvtyjbJBY/ruHofB1dPh1AxQX/cw=; | |
b=zKsPohaYyDetYYJjCt3wxX8ccq1Q0ziJUrb/QJtSyYc0UGrAixsCTfzB/ZLmiW3uNm | |
zeZOrkppcfhWVJbnR4B74N0pC5y9So1QNnAigC1rrJgi8Djzxt8l8ob3yEHDGyjdwKQJ | |
LnevkzMGL72VsUlc++FeLPWCI/rMaKLpwLEKFK2mGSGTImeQp1JR/0hjkFsS2f+yGfQb | |
Q4E+aoJU7nnEwoU4vKLwc3dLLiXYJiBUwwbvjPRTVhFl+ceDqrRf3cyVMNEEWaQB1Vaz | |
iWDMVeO0eu7ntfjKAuV0mnu4IgZcDfTwVh4KoHtbp3/PaiAqN6I8p7XPqnuc4PqTGk0P | |
eRZg== | |
MIME-Version: | 1.0 |
X-Received: | by 10.60.85.38 with SMTP id e6mr735410oez.65.1423185756056; Thu, |
05 Feb 2015 17:22:36 -0800 (PST) | |
Date: | Thu, 5 Feb 2015 20:22:36 -0500 |
Message-ID: | <CAOFvGD7pJTo8A=MXVbuuXO=++0vGukUyqVfckVtnCi99ziqWJQ@mail.gmail.com> |
Subject: | [geda-user] Using Lua to safely read configuration and layout files (program attached) |
From: | Jason White <whitewaterssoftwareinfo AT gmail DOT com> |
To: | geda-user AT delorie DOT com |
Reply-To: | geda-user AT delorie DOT com |
==Introduction== In the FOSDEM thread their currently is a raging discussion considering (among other things) the possibility of adding a modern scripting language such as Lua or Python to geda. This offers the exciting opportunity to make geda more accessible its many users. However, it also affords variety exciting new opportunities which I highlight below. Below I use Lua as an example, but this applies equally to other languages as well. However, I have written a demonstration of the concepts below using a C program with an embedded Lua interpreter. The link to try out the program is at the bottom of this email. ==(Safely) Hitting two birds with one stone== I wish to highlight two further uses beyond scripting that we could utilize a language such as Lua for. In addition to improved scripting, it also provides a robust pre-canned solution for the storage and retrieval of plain text information. I see two uses for this * Human readable configuration files * A more portable and maintainable file format for schematics and layouts. The advantage of using a scripting language as a storage mechanism for board information is that work flow automation become very easy since your board is literally nothing more than a variable that has been defined in the scripting language. Since the board is represented by an array, it makes it very easy to modify and autogenerate board information with Lua scripts. I would like to emphasize that when used for configuration and layout files, the Lua interpreter would not allow function calls, control structures, or loops to be executed; effectively only allowing variable definitions and math operations to take place. This is achieved in my example program by disabling the execution of the corresponding instructions in the Lua virtual machine. ==An Example Program (Written With Safety in Mind)== I would like to encourage everyone to try to make my example program behave in an unsafe manner using the Lua script that is read into it. I think you all will have a very difficult time making it do anything other than define variables since I added a "protected mode" to the interpreter. The "protected mode" disables the execution of function calls, loops, and control structures. This effectively makes it so that you can only define and reference variables in scripts with it enabled. Here is the link to download my example program. It is a simple C program which uses an embedded Lua interpreter to read arrays defined in a .lua file and print it to the console. https://drive.google.com/file/d/0BwP0qhqyaTIIVHl3UzcwSGFabGM/view?usp=sharing Type "./configure" then "make" to build it. Type "cd ./src" then "./example" to run it. ==Input and Feedback== I would like to hear your feedback! I see this as an efficient use of the tool. I figure, if we are going to have something like Lua, we may as well make use of it! Something like YAML brings in another dependency and makes is more difficult to use with scripts since it needs to be parsed first. -- Jason White
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |