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. 一步一步写一个简单通用的makefile(一)

    经常会用写一些小的程序有的是作为测试,但是每次都需要写一些简单的GCC 命令,有的时候移植一些项目中的部分代码到小程序里面进行测试,这个时候GCC 命令并不好些,如果写啦一个比较常用的makefile ...

  2. HDU 1159 Common Subsequence 公共子序列 DP 水题重温

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...

  3. 构建CMDB的一些启发

    开篇感言: 自从学习python自动化开发以来,一直都是从技术的角度来看待一切.以为技术就是王道.但显然我是一只井底之蛙.其实技术只不过是实现功能的工具而已,仅此而已.后来学习了解CMDB,越来越发现 ...

  4. python-面向对象(四)——类成员的访问方式汇总

    类成员的访问方式 #!/usr/bin/env python # _*_coding:utf-8 _*_ class pepole(object): '''This is __doc__ inform ...

  5. 集中式vs分布式

    Linus一直痛恨的CVS及SVN都是集中式的版本控制系统,而Git是分布式版本控制系统,集中式和分布式版本控制系统有什么区别呢? 先说集中式版本控制系统,版本库是集中存放在中央服务器的,而干活的时候 ...

  6. poj 1274 The Perfect Stall【匈牙利算法模板题】

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20874   Accepted: 942 ...

  7. 20169210《Linux内核原理与分析》第八周作业

    第一部分:实验 首先还是网易云课堂的学习,这次的课程是进程的创建和进程的描述. linux进程的状态与操作系统原理中的描述的进程状态有些不同,例如就绪状态和运行状态都是TASK_RUNNING. Li ...

  8. [Javascript + rxjs] Using the map method with Observable

    Like an array, Observable has a map method that allows us to transform a sequence into a new Observa ...

  9. php的ob_flush和flush(转)

    php.ini中 output_buffering = off 关闭php的缓存 implicit_flush = Off php不会立即输出到浏览器.如果是ON,相当于每次ECHO 立刻执行一个FL ...

  10. vxworks

    VxWorks 是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统.Tornado 是WRS 公司推出的一套实时操作系统开发环境,类似Mi ...