Showing 12 posts
This being Thanksgiving week in the U.S. and Google giving us Thursday and Friday off, I decided to take Monday to Wednesday off as well to spend some time hacking on Kyua — yes, finally, after months of being inactive. And what a three productive days!
Here comes a little briefing on the three fronts in which I made progress. (This puts on hold the header files series until next Monday… but most of you are probably away anyway. Enjoy the holidays if they apply to you!)
November 28, 2013
·
Tags:
atf, fedora, freebsd, kyua, lua
Continue reading (about
6 minutes)
In the previous post, I discussed the type-safe tree data structure that is now in the Kyua codebase, aimed at representing the configuration of the program. In this post, we’ll see how this data structure ties to the parsing of the configuration file.
One goal in the design of the configuration file was to make its contents a simple key/value association (i.e. assigning values to predetermined configuration variables). Of course, the fact that the configuration file is just a Lua script means that additional constructions (conditionals, functions, etc.) can be used to compute these values before assignment, but in the end all we want to have is a collection of values for known keys. The tree data structure does exactly the latter: maintain the mapping of keys to values, and ensuring that only a set of “valid” keys can be set. But, as a data structure, it does not contain any of the “logic” involved in computing those values: that is the job of the script.
June 2, 2012
·
Tags:
cxx, kyua, lua
Continue reading (about
3 minutes)
In the previous blog post, I described the problems that the implementation of the Kyua configuration file parsing and in-memory representation posed. I also hinted that some new code was coming and, after weeks of work, I’m happy to say that it has just landed in the tree!
I really want to get to explaining the nitty-gritty details of the implementation, but I’ll keep these for later. Let’s focus first on what the goals for the new configuration module were, as these drove a lot of the implementation details:
May 28, 2012
·
Tags:
cxx, kyua, lua
Continue reading (about
4 minutes)
As you may already know, RAII is a very powerful and popular pattern in the C++ language. With RAII, you can wrap non-stack-managed resources into a stack-managed object such that, when the stack-managed object goes out of scope, it releases the corresponding non-stack-managed object. Smart pointers are just one example of this technique, but so are IO streams too.
Before getting into the point of the article, bear with me for a second
while I explain what the
stack_cleaner
object of Lutok is. The “stack
cleaner” takes a reference to a Lua state and records the height of the
Lua stack on creation. When the object is destroyed (which happens when
the declaring function exits), the stack is returned to its previous
height thus ensuring it is clean. It is always a good idea for a
function to prevent side-effects by leaving its outside world as it was
— and, like it or not, the Lua state is part of the outside world
because it is an input/output parameter to many functions.
September 17, 2011
·
Tags:
cxx, lua, lutok
Continue reading (about
3 minutes)
It has finally happened. Lutok is the result of what was promised in the “Splitting utils::lua from Kyua” web post.
Quoting the project web page:
Lutok provides thin C++ wrappers around the Lua C API to ease the interaction between C++ and Lua. These wrappers make intensive use of RAII to prevent resource leakage, expose C++-friendly data types, report errors by means of exceptions and ensure that the Lua stack is always left untouched in the face of errors. The library also provides a small subset of miscellaneous utility functions built on top of the wrappers.
September 15, 2011 · Tags: announce, cxx, kyua, lua, lutok
Continue reading (about 2 minutes)
If you remember a post from January titled C++ interface to Lua for Kyua (wow, time flies), the Kyua codebase includes a small library to wrap the native Lua C library into a more natural C++ interface. You can take a look at the current code as of r129.
Quoting the previous post:
The utils::lua library provides thin C++ wrappers around the Lua C API to ease the interaction between C++ and Lua. These wrappers make intensive use of RAII to prevent resource leakage, expose C++-friendly data types, report errors by means of exceptions and ensure that the Lua stack is always left untouched in the face of errors. The library also provides a place (the operations module) to add miscellaneous utility functions built on top of the wrappers.
September 3, 2011 · Tags: cxx, kyua, lua
Continue reading (about 3 minutes)
The C++ interface to Lua
implemented in Kyua exposes a
lua::state class that wraps the lower-level lua_State* type. This
class completely hides the internal C type of Lua to ensure that all
calls that affect the state go through the lua::state class.
Things get a bit messy when we want to inject native functions into the
Lua environment. These functions follow the prototype represented by the
lua_CFunction type:
typedef int (*lua_CFunction)(lua_State*);
Now, let’s consider this code:
January 17, 2011
·
Tags:
cxx, kyua, lua
Continue reading (about
3 minutes)
About a week ago, I detailed the different approaches I encountered to deal with errors raised by the Lua C API. Later, I announced the new C++ interface for Lua implemented within Kyua. And today, I would like to talk about the specific mechanism I implemented in this library to deal with the Lua errors.
The first thing to keep in mind is that the whole purpose of Lua in the context of Kyua is to parse configuration files. This is an infrequent operation, so high performance does not matter: it is more valuable to me to be able to write robust algorithms fast than to have them run at optimal speed. The other key point to consider is that I want Kyua to be able to use prebuilt Lua libraries, which are built as C binaries.
January 14, 2011
·
Tags:
cxx, kyua, lua
Continue reading (about
3 minutes)
Finally! After two weeks of holidays work, I have finally been able to
submit Kyua’s
r39: a generic
library that implements a C++ interface to Lua.
The code is hosted in the
utils/lua/
subdirectory.
From the revision description:
The utils::lua library provides thin C++ wrappers around the Lua C API to ease the interaction between C++ and Lua. These wrappers make intensive use of RAII to prevent resource leakage, expose C++-friendly data types, report errors by means of exceptions and ensure that the Lua stack is always left untouched in the face of errors. The library also provides a place (the operations module) to add miscellaneous utility functions built on top of the wrappers.
January 8, 2011 · Tags: cxx, kyua, lua
Continue reading (about 2 minutes)
Some of the methods of the Lua C API can raise errors. To get an initial idea on what these are, take a look at the Functions and Types section and pay attention to the third field of a function description (the one denoted by ‘x’ in the introduction).
Dealing with the errors raised by these functions is tricky, not to say a nightmare. Also, the ridiculously-short documentation on this topic does not help. This post is dedicated to explain how these errors may be handled along with the advantages and disadvantages of each case.
January 7, 2011
·
Tags:
c, cxx, lua
Continue reading (about
6 minutes)
For the last couple of days, I have been playing around with the Lua C API and have been writing a thin wrapper library for C++. The main purpose of this auxiliary library is to ensure that global interpreter resources such as the global state or the execution stack are kept consistent in the presence of exceptions — and, in particular, that none of these are leaked due to programming mistakes when handling error codes.
December 27, 2010
·
Tags:
c, cxx, kyua, lua
Continue reading (about
6 minutes)
Over a week ago, I mostly finished the implementation of the runtime engine for test cases of Kyua and, along the way, realized that it is imperative to write a configuration system right now before the configuration code becomes messier than it already is.
To that end, I spent the last week working on a design document for the configuration system. Summarizing, the document describes what the requirements for the configuration files of Kyua are, what the possible alternatives to implement them are, and advocates the use of Lua — a tiny embedded programming language — to bring these configuration files to life.
December 22, 2010
·
Tags:
kyua, lua
Continue reading (about
1 minute)