local form = {_tag = 'form'}
function form.build(tag, super)
local target = {
_tag = tag,
_super = super
}
form.spec(target)
setmetatable(target, form._meta())
return target
end function form.on(target, spec)
local tar = {}
for k,v in pairs(spec) do
if type(v) == 'function' then
local method = target[k] or spec[k]
tar[k] = function ( ... )
method(target, ...)
end
else
tar[k] = v
end
end
return tar
end function form.spec(target)
target.tag = target.tag or form.tag
function target:on(target)
local tar = {}
local spec = self
for k,v in pairs(spec) do
if type(v) == 'function' then
tar[k] = function ( ... )
spec[k](target, ...)
end
else
tar[k] = v
end
end
print(target:tag()..'['..spec._tag..'] target binding form produced')
-- no such key binding to the target
tar.on = nil
tar.spec = nil
return tar
end
function target:spec(prop, target)
if self._interface == nil then
self._interface = {}
end
local handler = {}
function handler.string(self, prop, target)
if target ~= nil then
print(self:tag()..'['..prop..'] setter/getter produced')
local property = '_'..prop
local function prop_(self, target)
if target ~= nil then
self[property] = target
return self
end
return self[property]
end
prop_(self, target)[prop] = prop_
end
local spec = self[prop](self)
return spec and spec:on(self)
end
function handler.table(self, prop)
local target = prop
table.insert(self._interface, target)
if type(target._tag)=='string' then
print(self:tag()..' interface['..target._tag..'] specified')
end
return self
end
local handler_prop = handler[type(prop)]
return handler_prop and handler_prop(self, prop, target)
end
return target
end function form:tag()
local tag = self._tag
if type(tag)=='string'
then
return '*'..tag..'*'
end
return 'none.TAG'
end function form._meta()
local meta = {}
function meta.__index(target, key)
-- avoid target._interface rise to C stack overflow, .etc
-- following anonymous table specify the key filters
if ({_interface = true, _super = true})[key] then return nil end local super = target._super
local interface = target._interface
local v = super and super[key]
if v == nil and type(interface)=='table'
then
for i=, #interface do
v = interface[i][key]
if v ~= nil then return v end
end
end
return v
end
return meta
end return form

[Lua]索引极致,form.lua的更多相关文章

  1. [Lua]表驱动索引编程,form.lua

    form.interface local form = {_tag = 'form'} function form.build(tag, super) --[[ -- form to produce ...

  2. (转) Lua使用心得一 LUA和VC整合

    这几天研究了一下lua,主要关注的是lua和vc之间的整合,把代码都写好放在VC宿主程序里,然后在lua里调用宿主程序的这些代码(或者叫接口.组件,随便你怎么叫),希望能用脚本来控制主程序的行为.这实 ...

  3. Embedding Lua in C: Using Lua from inside C.

    Requirments:     1: The Lua Sources.    2: A C compiler - cc/gcc/g++ for Unix, and Visual C++ for Wi ...

  4. cocos2dx lua binding ,cocos2dx 绑定lua测试

    前面2篇分别简单介绍 手动bind C++ 类和lua:http://blog.csdn.net/chenee543216/article/details/12074771 使用tolua++简化工作 ...

  5. 整理Lua和Unity和Lua交互文章链接

    重点文章: 1.[Unity3D]Unity3D游戏开发之Lua与游戏的不解之缘(上) 2.[Unity3D]Unity3D游戏开发之Lua与游戏的不解之缘(中) 3.Lua和C++交互详细总结 4. ...

  6. lua脚本之lua语言简介以及lua的安装

    本博主不擅于进行文字创作,所以,相当一部分文字皆复制于其他博文.还希望能够得到谅解.  一.Lua语言简介 Lua是一个免费的开源软件,可以免费用于科研及商业.Lua具有一个专家团队在维护和升级,其设 ...

  7. Android错误:can not get file data of lua/start_v2.op [LUA ERROR] [string "require "lua/start_v2””] 已解决

    错误: can not get file data of lua/start_v2.op [LUA ERROR] [string "require "lua/start_v2””] ...

  8. 【Lua】linux下lua+mod_lwt环境搭建

    Lua 是一个小巧的脚本语言.它具有轻量级.可扩展等优势.它可以作为一个强大.轻量的脚本语言,供任何需要的程序使用. LWT (Lua Web Tools) 可让你使用 Lua 开发 Web 应用,并 ...

  9. [Lua快速了解一下]Lua运行

    -Lua的Hello World print("Hello World") 分号可选 -类似python,进入Lua后再shell中打命令执行语句也可 > print(&qu ...

随机推荐

  1. Python串口操作纸币器1

    公司需要纸币器开发,参考纸币器文档和网上的一篇vb版本,代码如下: # -*- coding:utf-8 -*- # Author: Pete Yim<xpHook@gmail.com> ...

  2. Vi和Vim的区别及联系

    它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅兼容vi的所有指令,而且还有一些新的特性在里面.vim的这些优势主要体现在以下几个方面:1.多级撤消我们知道在vi里,按 u只能撤消上次命 ...

  3. phonegap与微信开放平台接口整合

    在开发phonegap应用的过程中有个需求需要将应用的消息推送到微信上.于是我自己写了一个微信的phonegap插件,并成功整合进了应用. 插件地址:https://github.com/ajccom ...

  4. Oracle的OFA架构

    最优灵活体系结构(Optimal Flexible Architecture,简称OFA) OFA其实就是一种Oracle的一种规范,其意义就是用一种统一的给文件和文件夹的规则,和文件存放目录的规则做 ...

  5. BOM、DOM学习笔记——JavaScript

    1.BOM的概述    browser object modal :浏览器对象模型.    浏览器对象:window对象.    Window 对象会在 <body> 或 <fram ...

  6. Http(3)

    响应行 1.常见的状态: 200:表示请求处理完美返回 302:表示请求需要经进一步细化 404:表示客户访问的资源找不到. 500: 表示服务器的资源发送错误.(服务器内部错误) 2.常见的响应头 ...

  7. 转 python 之 分割参数getopt

    python 之 分割参数getopt os下有个方法walk,非常的好用,用来生成一个generator.每次可以得到一个三元tupple,其中第一个为起始路径,第二个为起始路径下的文件夹,第三个是 ...

  8. 用C#实现通用守护进程

    1. 下载 源码下载:http://pan.baidu.com/s/1vqDA2 安装包下载:http://pan.baidu.com/s/1sjmEB0p 2. 安装注意事项 在配置档中配置你要守护 ...

  9. resin 4.0数据源的配置

    在resin 的conf 文件下有resin.xml  我们在这里能够配置数据源以及配置项目 一.配置多个数据源,多个项目共享这些数据源.也就是这些数据源配置在<host>   </ ...

  10. 清理300多台MySQL数据库的过期binlog日志

    早晨睡梦中,被 on-call了,说磁盘报警,赶紧起来打开email,收到上百封email报警,数据库磁盘不够了,查询了原因 [xxx@xxxx cacti]$ ssh xxxx "df - ...