随笔分类 -  Lua

摘要:int lua_next (lua_State *L, int index);Pops a key from the stack, and pushes a key-value pair from the table at the given index (the "next" pair after the given key). If there are no more elements in the table, thenlua_nextreturns 0 (and pushes nothing).A typical traversal looks like this: 阅读全文
posted @ 2013-03-20 19:29 good90 阅读(715) 评论(0) 推荐(0)
摘要:cpFile.lua 1 function copyfile(source, destination) 2 sourcefile = io.open(source,"r") 3 assert(sourcefile) 4 destinationfile = io.open(destination,"w") 5 assert(destinationfile) 6 for line in sourcefile:lines() do 7 print(line) 8 destinationfile:write(line) 9 destinationfile:wri 阅读全文
posted @ 2012-08-26 22:49 good90 阅读(3278) 评论(0) 推荐(0)
摘要:记下两篇写的不错的文章:http://www.cnblogs.com/whiteyun/archive/2009/09/02/1541043.htmlhttp://blog.csdn.net/blueboy2000/article/details/5441745 阅读全文
posted @ 2012-08-26 17:53 good90 阅读(241) 评论(0) 推荐(0)
摘要:先看代码: 1 function permgen (a, n) 2 if 0 == n then 3 printResult(a) 4 else 5 for i=1,n do 6 a[n], a[i] = a[i], a[n] 7 permgen(a, n -1) 8 a[n], a[i] = a[i], a[n] 9 end10 end11 end12 13 function printResult (a)14 for i,v in ipairs(a) do15 ... 阅读全文
posted @ 2012-08-19 12:04 good90 阅读(6825) 评论(0) 推荐(1)
摘要:首先配置环境,百度文库里这个讲的很详细http://wenku.baidu.com/view/7912da3667ec102de2bd8957.html环境配置好之后,我也写了个简单的调用main.cpp 1 #include <stdio.h> 2 3 extern "C"{ 4 #include "lua.h" 5 #include "lualib.h" 6 #include "lauxlib.h" 7 }; 8 9 10 lua_State *L;11 int luaAdd(int x, int 阅读全文
posted @ 2012-08-19 00:11 good90 阅读(22545) 评论(2) 推荐(0)
摘要:看下面一个简单例1 function fac(n)2 if n == 0 then3 return 14 else5 return fac(n-1)6 end7 end像这种在函数的末尾返回一个函数就是尾调用,这个尾调用并不像C++函数调用一样需要额外的堆栈空间,而是相对于g... 阅读全文
posted @ 2012-08-09 22:09 good90 阅读(2531) 评论(5) 推荐(0)