<?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>可可熊的窝 &#187; Lua</title>
	<atom:link href="http://cocobear.info/blog/category/my-programming/lua/feed/" rel="self" type="application/rss+xml" />
	<link>http://cocobear.info/blog</link>
	<description>K.I.S.S</description>
	<lastBuildDate>Sat, 10 Dec 2011 16:11:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>读完了Programming in Lua (first edition)</title>
		<link>http://cocobear.info/blog/2009/04/08/read-programming-in-lua-first-edition/</link>
		<comments>http://cocobear.info/blog/2009/04/08/read-programming-in-lua-first-edition/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 08:19:11 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Lua]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=613</guid>
		<description><![CDATA[花了差不多两周的时间读完了Lua Programming in Lua (first edition) ，没找到pdf格式的，一直在官网在线看的，不是很舒服。看的似乎有点慢，里面的英文很简单，讲的内容难点也不多，也没有太多的代码去动手实践，似乎是受别人打击了:-)（看到人家博客里写道：“花两天的时间过了一遍PIL”）。 Lua作为一个脚本语言在很多地方与Python有相似之处，不过小巧了很多，数据类型、表达式、语句等都很精简，但是这并不影响Lua成为一个流行的脚本语言，灵活的table成就了Lua的强大，table可以演化出list,dict，更强大的是table可以实现OO，Lua并没有在语言级提供OO的实现，不过Lua的作者在PIL中展示了使用table完全可以实现近乎完美的OO编程，我觉得这是对整天鼓吹OO思想的人一个极大讽刺，OO其实没什么，C语言中使用结构体，函数指针也可以有模有样的进行OO编程。 Lua中也有很多函数式编程语言的影子，所以很多人把Lua和Scheme归为了近亲，不过俺不了解Scheme，对函数式编程也是一知半解，只能凑个热闹。 Lua之所以在游戏中使用比较广泛，是因为它可以很好的和C/C++结合在一起，可以很方便的互操作，通过使用Stack的方式。还有一个很重要的原因，Lua提供的是搭积木的原料，而不是搭好的建筑，所以你可以很灵活的用自己的方式去写程序。比如你可以用table实现一个完整的OO系统，然后在OO上面写程序(这里有一点很重要，基于table实现OO是很轻量的，而不是语言级的OO)；你也可以用metatable来实现Python中很强大的filter,map,reduce。 Lua中的table有点类似道家学说里面的&#8221;道&#8221;,&#8221;道生一，一生二，二生三，三生万物&#8221;，而table就是Lua中的“道”。 还得提一点Lua是完全用ANSI C编写的。 cocobear@0-0 /home/cocobear/Codes/lua-5.1.4/src $ wc *.c *.h -l &#124; tail -1 17002 total]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2009/04/08/read-programming-in-lua-first-edition/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Python与Lua分别实现一个计数器</title>
		<link>http://cocobear.info/blog/2009/03/31/write-a-counter-with-python-and-lua/</link>
		<comments>http://cocobear.info/blog/2009/03/31/write-a-counter-with-python-and-lua/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 04:47:15 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Lua]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=591</guid>
		<description><![CDATA[Lua: &#62; function newCounter () &#62;&#62; local i = 0 &#62;&#62; return function () -- anonymous function &#62;&#62; i = i + 1 &#62;&#62; return i &#62;&#62; end &#62;&#62; end &#62; &#62; c1 = newCounter() &#62; print(c1()) 1 &#62; print(c1()) 2 Lua同Python类似，也可以嵌套定义函数，不过Lua嵌套函数可以访问上层闭包函数的局部变量，而在这个内嵌函数中这些变量不是全局变量，也不是局部变量，而是一种upvalue，与C语言中的static修饰的变量类似，所以在这里可以利用这个特性完成这个计数器。 Python: &#62;&#62;&#62; def counter(last=[1]): ... next = last[0] + 1 ... last[0] = [...]]]></description>
		<wfw:commentRss>http://cocobear.info/blog/2009/03/31/write-a-counter-with-python-and-lua/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

