<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
  <title>Marcus Irven's Blog</title>
  <subtitle>Marcus Irven's Blog</subtitle>
  <link href="http://www.marcusirven.com//" rel="self" />
  <link href="http://www.marcusirven.com/" />
  <updated>2011-01-22T22:33:52-06:00</updated>
  <author>
    <name>Marcus Irven</name>
    <email>marcus@marcusirven.com</email>
  </author>
  <id>http://www.marcusirven.com/</id>
  
  <entry>
    <title>Dangers of lua_error when using C++</title>
    <link href="/blog/2009/02/19/dangers-of-lua_error-when-using-c++.html" />
    <id>tag:www.marcusirven.com,2009-02-19:1235073390</id>
    <updated>2009-02-19T13:56:30-06:00</updated>
    <content type="html">&lt;p&gt;By default Lua uses &lt;a href=&quot;http://en.wikipedia.org/wiki/Longjmp&quot; title=&quot;&quot;&gt;longjmp&lt;/a&gt; when &lt;a href=&quot;http://www.lua.org/manual/5.1/manual.html#lua_error&quot; title=&quot;&quot;&gt;lua_error&lt;/a&gt; or &lt;a href=&quot;http://www.lua.org/manual/5.1/manual.html#luaL_error&quot; title=&quot;&quot;&gt;luaL_error&lt;/a&gt; is called, this can produce subtle bugs or memory leaks in C++ if you are not careful.&lt;/p&gt;
&lt;p&gt;Take the following code, which simply calls the foo function which creates an object on the stack and throws an error:&lt;/p&gt;
&lt;div class=&quot;UltraViolet&quot;&gt;
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; #&lt;span class=&quot;Keyword&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;lt;&lt;/span&gt;iostream&lt;span class=&quot;String&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt; &lt;span class=&quot;Storage&quot;&gt;extern&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;C&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; {
&lt;span class=&quot;line-numbers&quot;&gt;   4 &lt;/span&gt;     #&lt;span class=&quot;Keyword&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;lua.h&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   5 &lt;/span&gt;     #&lt;span class=&quot;Keyword&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;lualib.h&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   6 &lt;/span&gt;     #&lt;span class=&quot;Keyword&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;lauxlib.h&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   7 &lt;/span&gt; }
&lt;span class=&quot;line-numbers&quot;&gt;   8 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;   9 &lt;/span&gt; &lt;span class=&quot;Storage&quot;&gt;class&lt;/span&gt; Obj {
&lt;span class=&quot;line-numbers&quot;&gt;  10 &lt;/span&gt; &lt;span class=&quot;Storage&quot;&gt;public&lt;/span&gt;:
&lt;span class=&quot;line-numbers&quot;&gt;  11 &lt;/span&gt;     &lt;span class=&quot;FunctionName&quot;&gt;Obj&lt;/span&gt;() {
&lt;span class=&quot;line-numbers&quot;&gt;  12 &lt;/span&gt;         std::cout &amp;lt;&amp;lt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;object create&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &amp;lt;&amp;lt; std::endl;
&lt;span class=&quot;line-numbers&quot;&gt;  13 &lt;/span&gt;     }
&lt;span class=&quot;line-numbers&quot;&gt;  14 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;  15 &lt;/span&gt;     &lt;span class=&quot;FunctionName&quot;&gt;~Obj&lt;/span&gt;() {
&lt;span class=&quot;line-numbers&quot;&gt;  16 &lt;/span&gt;         std::cout &amp;lt;&amp;lt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;object destroy&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &amp;lt;&amp;lt; std::endl;
&lt;span class=&quot;line-numbers&quot;&gt;  17 &lt;/span&gt;     }
&lt;span class=&quot;line-numbers&quot;&gt;  18 &lt;/span&gt; };
&lt;span class=&quot;line-numbers&quot;&gt;  19 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;  20 &lt;/span&gt; &lt;span class=&quot;Storage&quot;&gt;int&lt;/span&gt; foo(lua_State*L) {
&lt;span class=&quot;line-numbers&quot;&gt;  21 &lt;/span&gt;     Obj obj;
&lt;span class=&quot;line-numbers&quot;&gt;  22 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;return&lt;/span&gt; luaL_error(L, &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;error in foo&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;);   
&lt;span class=&quot;line-numbers&quot;&gt;  23 &lt;/span&gt; }
&lt;span class=&quot;line-numbers&quot;&gt;  24 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;  25 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;  26 &lt;/span&gt; &lt;span class=&quot;Storage&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;FunctionName&quot;&gt;ma&lt;span class=&quot;FunctionName&quot;&gt;in&lt;/span&gt;&lt;/span&gt;(&lt;span class=&quot;Storage&quot;&gt;int&lt;/span&gt; argc, &lt;span class=&quot;Storage&quot;&gt;char&lt;/span&gt;** argv) {
&lt;span class=&quot;line-numbers&quot;&gt;  27 &lt;/span&gt;     lua_State* L = lua_open();
&lt;span class=&quot;line-numbers&quot;&gt;  28 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;  29 &lt;/span&gt;     lua_pushcfunction(L, foo);
&lt;span class=&quot;line-numbers&quot;&gt;  30 &lt;/span&gt;     &lt;span class=&quot;Storage&quot;&gt;int&lt;/span&gt; r = lua_pcall(L, &lt;span class=&quot;Number&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;Number&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;Number&quot;&gt;0&lt;/span&gt;);
&lt;span class=&quot;line-numbers&quot;&gt;  31 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;  32 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;if&lt;/span&gt; (r == LUA_ERRRUN) {
&lt;span class=&quot;line-numbers&quot;&gt;  33 &lt;/span&gt;         std::cout &amp;lt;&amp;lt; lua_tostring(L, -&lt;span class=&quot;Number&quot;&gt;1&lt;/span&gt;) &amp;lt;&amp;lt; std::endl;
&lt;span class=&quot;line-numbers&quot;&gt;  34 &lt;/span&gt;     }
&lt;span class=&quot;line-numbers&quot;&gt;  35 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;  36 &lt;/span&gt;     lua_close(L);
&lt;span class=&quot;line-numbers&quot;&gt;  37 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;Number&quot;&gt;0&lt;/span&gt;;
&lt;span class=&quot;line-numbers&quot;&gt;  38 &lt;/span&gt; }
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;When compiled against the default build of the Lua library and run you get the following output:&lt;/p&gt;
&lt;div class=&quot;UltraViolet&quot;&gt;
&lt;pre class=&quot;active4d&quot;&gt;$ g++ main.cpp -llua -o example
$ ./example 
object create
error in foo
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice the destructor was never called on obj.  However if you build Lua as C++ then lua_error() will be implemented using C++ exceptions which will cause the stack to clean up as expected.&lt;/p&gt;
&lt;p&gt;On my Mac I built Lua as C++ with the following command:&lt;/p&gt;
&lt;div class=&quot;UltraViolet&quot;&gt;
&lt;pre class=&quot;active4d&quot;&gt;make macosx -e CC=g++
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I&amp;#8217;ve built Lua on Windows as C++ as well, in Visual Studio there is a setting to compile sources as C++ rather than by file extensions which is the default.  Now when building and running you get the output you would expected:&lt;/p&gt;
&lt;div class=&quot;UltraViolet&quot;&gt;
&lt;pre class=&quot;active4d&quot;&gt;$ g++ main.cpp -llua -o example
$ ./example
object create
object destroy
error in foo
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;One other thing to note is that the extern &amp;#8220;C&amp;#8221; around the Lua includes is no longer needed after building the Lua library as C++.  If you can&amp;#8217;t rebuild the Lua library for some reason or another than you just need to be aware and make sure everything is cleaned up before calling lua_error() or luaL_error().&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <title>Comparing Ruby Fibers to Lua Coroutines</title>
    <link href="/blog/2009/02/19/comparing-ruby-fibers-to-lua-coroutines.html" />
    <id>tag:www.marcusirven.com,2009-02-19:1235066253</id>
    <updated>2009-02-19T11:57:33-06:00</updated>
    <content type="html">&lt;p&gt;One of the more interesting features of Lua are &lt;a href=&quot;http://en.wikipedia.org/wiki/Coroutine&quot;&gt;coroutines&lt;/a&gt;.  One of the new features in Ruby 1.9 are &lt;a href=&quot;http://www.infoq.com/news/2007/08/ruby-1-9-fibers&quot;&gt;fibers&lt;/a&gt; which are exactly the same thing, in fact they even borrowed the resume/yield method names from Lua.  The following Ruby code:&lt;/p&gt;
&lt;div class=&quot;UltraViolet&quot;&gt;
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; fib &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;LibraryClassType&quot;&gt;Fiber&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do  &lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt;     x, y &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;Number&quot;&gt;1&lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;loop&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do  &lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   4 &lt;/span&gt;         &lt;span class=&quot;LibraryClassType&quot;&gt;Fiber&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;yield&lt;/span&gt; y 
&lt;span class=&quot;line-numbers&quot;&gt;   5 &lt;/span&gt;         x,y &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; y,x&lt;span class=&quot;Operator&quot;&gt;+&lt;/span&gt;y 
&lt;span class=&quot;line-numbers&quot;&gt;   6 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;   7 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;   8 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;   9 &lt;/span&gt; &lt;span class=&quot;Number&quot;&gt;20&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;times&lt;/span&gt; { puts fib.&lt;span class=&quot;FunctionName&quot;&gt;resume&lt;/span&gt; }
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;is roughly equivalent to the following Lua code:&lt;/p&gt;
&lt;div class=&quot;UltraViolet&quot;&gt;
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; fib &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;CommandMethod&quot;&gt;coroutine.create&lt;/span&gt;(&lt;span class=&quot;Keyword&quot;&gt;function&lt;/span&gt;()
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;local&lt;/span&gt; x, y &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;Number&quot;&gt;1&lt;/span&gt; 	
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;BuiltInConstant&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   4 &lt;/span&gt;         &lt;span class=&quot;CommandMethod&quot;&gt;coroutine.yield&lt;/span&gt;(y)
&lt;span class=&quot;line-numbers&quot;&gt;   5 &lt;/span&gt;         x,y &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; y,x&lt;span class=&quot;Operator&quot;&gt;+&lt;/span&gt;y 		
&lt;span class=&quot;line-numbers&quot;&gt;   6 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   7 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;)
&lt;span class=&quot;line-numbers&quot;&gt;   8 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;   9 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;for&lt;/span&gt; i&lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;Number&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;Number&quot;&gt;20&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;do&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;  10 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;local&lt;/span&gt; _, value &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;CommandMethod&quot;&gt;coroutine.resume&lt;/span&gt;(fib)
&lt;span class=&quot;line-numbers&quot;&gt;  11 &lt;/span&gt;     &lt;span class=&quot;CommandMethod&quot;&gt;print&lt;/span&gt;(value)
&lt;span class=&quot;line-numbers&quot;&gt;  12 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content>
  </entry>
  
  <entry>
    <title>Null Smart Pointers Using Boost</title>
    <link href="/blog/2009/02/15/null-smart-pointers-using-boost.html" />
    <id>tag:www.marcusirven.com,2009-02-15:1234724143</id>
    <updated>2009-02-15T12:55:43-06:00</updated>
    <content type="html">&lt;p&gt;Managing memory is one of the pains that comes with developing in C++.  Smart pointers such as std::auto_ptr help make things easier but they come with their own issues.  My smart pointer implementation of choice is boost&amp;#8217;s shared_ptr.  A pattern I have found useful is:&lt;/p&gt;
&lt;div class=&quot;UltraViolet&quot;&gt;
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; &lt;span class=&quot;Storage&quot;&gt;class&lt;/span&gt; Foo
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt; {
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt; &lt;span class=&quot;Storage&quot;&gt;public&lt;/span&gt;:
&lt;span class=&quot;line-numbers&quot;&gt;   4 &lt;/span&gt;     &lt;span class=&quot;Storage&quot;&gt;typedef&lt;/span&gt; boost::shared_ptr&amp;lt;Foo&amp;gt; &lt;span class=&quot;LibraryClassType&quot;&gt;Ptr&lt;/span&gt;;
&lt;span class=&quot;line-numbers&quot;&gt;   5 &lt;/span&gt;     &lt;span class=&quot;Storage&quot;&gt;static&lt;/span&gt; Foo::&lt;span class=&quot;LibraryClassType&quot;&gt;Ptr&lt;/span&gt; Null;
&lt;span class=&quot;line-numbers&quot;&gt;   6 &lt;/span&gt; &lt;span class=&quot;Storage&quot;&gt;public&lt;/span&gt;:
&lt;span class=&quot;line-numbers&quot;&gt;   7 &lt;/span&gt;     &lt;span class=&quot;LineComment&quot;&gt;&lt;span class=&quot;LineComment&quot;&gt;//&lt;/span&gt; rest of declaration&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   8 &lt;/span&gt; };
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And then one can use them like:&lt;/p&gt;
&lt;div class=&quot;UltraViolet&quot;&gt;
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; &lt;span class=&quot;Storage&quot;&gt;void&lt;/span&gt; f(Foo::&lt;span class=&quot;LibraryClassType&quot;&gt;Ptr&lt;/span&gt; foo)
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt; {
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;if&lt;/span&gt; (foo == Foo::Null) 
&lt;span class=&quot;line-numbers&quot;&gt;   4 &lt;/span&gt;     {
&lt;span class=&quot;line-numbers&quot;&gt;   5 &lt;/span&gt;         &lt;span class=&quot;LineComment&quot;&gt;&lt;span class=&quot;LineComment&quot;&gt;//&lt;/span&gt; handle null case&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   6 &lt;/span&gt;     }
&lt;span class=&quot;line-numbers&quot;&gt;   7 &lt;/span&gt; }
&lt;/pre&gt;
&lt;/div&gt;</content>
  </entry>
  
  <entry>
    <title>Introducing luaspec</title>
    <link href="/blog/2009/02/15/introducing-luaspec.html" />
    <id>tag:www.marcusirven.com,2009-02-15:1234725748</id>
    <updated>2009-02-15T13:22:28-06:00</updated>
    <content type="html">&lt;p&gt;I&amp;#8217;ve been doing a lot of work with &lt;a href=&quot;http://www.lua.org/&quot;&gt;Lua&lt;/a&gt; over the past couple of years.  Originally I used &lt;a href=&quot;http://phil.freehackers.org/programs/luaunit/index.html&quot;&gt;luaunit&lt;/a&gt; for unit testing.  This has worked ok, but I&amp;#8217;ve used &lt;a href=&quot;http://rspec.info/&quot;&gt;RSpec&lt;/a&gt; while working with Ruby and have come to appreciate the specification style syntax and the different mindset it invokes while writing tests.  So I introduce to you &lt;a href=&quot;http://github.com/mirven/luaspec/&quot;&gt;luaspec&lt;/a&gt;, a &lt;a href=&quot;http://behaviour-driven.org/&quot;&gt;behaviour-driven design&lt;/a&gt; framework for Lua.&lt;/p&gt;
&lt;div class=&quot;UltraViolet&quot;&gt;
&lt;pre class=&quot;active4d&quot;&gt;&lt;span class=&quot;line-numbers&quot;&gt;   1 &lt;/span&gt; &lt;span class=&quot;CommandMethod&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;luaspec&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   2 &lt;/span&gt; 
&lt;span class=&quot;line-numbers&quot;&gt;   3 &lt;/span&gt; describe[&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;Account, withdrawing funds&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;] &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;function&lt;/span&gt;()
&lt;span class=&quot;line-numbers&quot;&gt;   4 &lt;/span&gt;     before &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;function&lt;/span&gt;()
&lt;span class=&quot;line-numbers&quot;&gt;   5 &lt;/span&gt;         account &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; Account:new { balance &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Number&quot;&gt;100&lt;/span&gt; }
&lt;span class=&quot;line-numbers&quot;&gt;   6 &lt;/span&gt;         account:withdraw(&lt;span class=&quot;Number&quot;&gt;10&lt;/span&gt;)
&lt;span class=&quot;line-numbers&quot;&gt;   7 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;   8 &lt;/span&gt;     
&lt;span class=&quot;line-numbers&quot;&gt;   9 &lt;/span&gt;     it[&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;should remove the withdrawal amount from the balance&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;] &lt;span class=&quot;Operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;function&lt;/span&gt;()
&lt;span class=&quot;line-numbers&quot;&gt;  10 &lt;/span&gt;         expect(account.balance).should_be(&lt;span class=&quot;Number&quot;&gt;90&lt;/span&gt;)
&lt;span class=&quot;line-numbers&quot;&gt;  11 &lt;/span&gt;     &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;line-numbers&quot;&gt;  12 &lt;/span&gt; &lt;span class=&quot;Keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It supports nested contexts, before and after functions, and has built-in support for mocking.  More articles coming in the upcoming days describing all the functionality fully.&lt;/p&gt;</content>
  </entry>
  
</feed>
