<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chryzo's Notepad &#187; LUA</title>
	<atom:link href="http://www.chryzo.net/tag/lua/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chryzo.net</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 20 Jul 2010 19:08:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>LUA: Classes and Instanciations</title>
		<link>http://www.chryzo.net/2009/04/lua-classes-and-instanciations/</link>
		<comments>http://www.chryzo.net/2009/04/lua-classes-and-instanciations/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 19:46:17 +0000</pubDate>
		<dc:creator>Chryzo</dc:creator>
				<category><![CDATA[LUA]]></category>

		<guid isPermaLink="false">http://www.chryzo.net/?p=80</guid>
		<description><![CDATA[If, like me, you tend to be a bottom up learner you usually never read the manuals except when you need to. And this is, for once, one of these times. Only reading the class parts of the manuals/wikis (IE: http://lua-users.org/wiki/SimpleLuaClasses and http://www.lua.org/pil/16.1.html ) is actually not really enough to be able to make classes [...]]]></description>
			<content:encoded><![CDATA[<p>If, like me, you tend to be a bottom up learner you usually never read the manuals except when you need to. And this is, for once, one of these times. Only reading the class parts of the manuals/wikis (IE: http://lua-users.org/wiki/SimpleLuaClasses and http://www.lua.org/pil/16.1.html ) is actually not really enough to be able to make classes always work as you want them to.<br />
If you also tend to adapt examples to your requirements (no need to reinvent the wheel), here it might actually go wrong. In the examples given in the two previous link, the writers tended to forget about the differences between metatables and tables completely confounding me <img src='http://www.chryzo.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
In the example below:</p>
<blockquote><p>
    function Account:new (o)<br />
      o = o or {}   &#8212; create object if user does not provide one<br />
      setmetatable(o, self)<br />
      self.__index = self<br />
      return o<br />
    end
</p></blockquote>
<p>self equals Account and the metatable of Account is also Account which creates an infinite loop which needs to be treated if you try to save / dump the instanced variables.<br />
To solve this, use instead the following syntax:</p>
<blockquote><p>
    function Account:new (o)<br />
      o = o or {}   &#8212; create object if user does not provide one<br />
      setmetatable(o, {__index = self})<br />
      return o<br />
    end
</p></blockquote>
<p>When you retrieve the saved variables don&#8217;t forget to set the metatables to what they should be too <img src='http://www.chryzo.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And if I am totally wrong in what I just posted, I ll be glad to be corrected. I really do have a hard time with the Lua OOP model, guess I still have lots to read / learn.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chryzo.net/2009/04/lua-classes-and-instanciations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LUA and overloading</title>
		<link>http://www.chryzo.net/2009/04/lua-and-overloading/</link>
		<comments>http://www.chryzo.net/2009/04/lua-and-overloading/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 19:27:15 +0000</pubDate>
		<dc:creator>Chryzo</dc:creator>
				<category><![CDATA[LUA]]></category>

		<guid isPermaLink="false">http://www.chryzo.net/?p=68</guid>
		<description><![CDATA[I am coding some mod in LUA for some game and I hit a snag and it actually took me quite some time to solve it due to several functionalities not available through LUA to control some of the interface elements and thus transformed the snag into lots of small snags to get what I [...]]]></description>
			<content:encoded><![CDATA[<p>I am coding some mod in LUA for some game and I hit a snag and it actually took me quite some time to solve it due to several functionalities not available through LUA to control some of the interface elements and thus transformed the snag into lots of small snags to get what I wanted to work.</p>
<p>But the last snag I hit, after clearing the others, was really annoying, in the API there was a function like: removeSmthg(ID) but also removeSmthg(NAME). And being unfamiliar with the language as always I forgot that <strong>LUA doesn&#8217;t handle type-based function overloading</strong>, so only one of the function actually worked&#8230; the one I was not using. Once I found that out, it ended up being quite easy to actually do what I wanted at the start.</p>
<p>And because it is blogged, I should remember it next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chryzo.net/2009/04/lua-and-overloading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
