摘要: --sort中的匿名函数中的grades称为外部局部变量,或者upvalue--函数内部定义的函数可以访问函数的变量--这个就是简单的闭包--function sortbygrade (names, grades)-- table.sort(names, function(n1, n2)-- ... 阅读全文
posted @ 2015-03-09 20:50 zzyoucan 阅读(117) 评论(0) 推荐(0) 编辑
摘要: Set = {}Set.mt = {}--定义普通的表作为元表,为了避免命名污染直接放在Set内部function Set.new(t) local set = {} setmetatable(set, Set.mt)--一组相关的表共享一个metatable(通过这个可以描述他们共同的... 阅读全文
posted @ 2015-03-09 15:44 zzyoucan 阅读(264) 评论(0) 推荐(0) 编辑
摘要: #include #include #define MAX_COLOR 255 extern "C"{#include "lua-5.2.2/src/lauxlib.h"#include "lua-5.2.2/src/lualib.h"#include "lua-5.2.2/src/ls... 阅读全文
posted @ 2015-03-09 11:42 zzyoucan 阅读(1966) 评论(0) 推荐(0) 编辑
摘要: #include #define MAX_COLOR 255 extern "C"{#include "lua-5.2.2/src/lauxlib.h"#include "lua-5.2.2/src/lualib.h"#include "lua-5.2.2/src/lstate.h"}i... 阅读全文
posted @ 2015-03-09 00:05 zzyoucan 阅读(6158) 评论(0) 推荐(0) 编辑