[Lua]索引极致,form.lua
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的更多相关文章
- [Lua]表驱动索引编程,form.lua
form.interface local form = {_tag = 'form'} function form.build(tag, super) --[[ -- form to produce ...
- (转) Lua使用心得一 LUA和VC整合
这几天研究了一下lua,主要关注的是lua和vc之间的整合,把代码都写好放在VC宿主程序里,然后在lua里调用宿主程序的这些代码(或者叫接口.组件,随便你怎么叫),希望能用脚本来控制主程序的行为.这实 ...
- 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 ...
- cocos2dx lua binding ,cocos2dx 绑定lua测试
前面2篇分别简单介绍 手动bind C++ 类和lua:http://blog.csdn.net/chenee543216/article/details/12074771 使用tolua++简化工作 ...
- 整理Lua和Unity和Lua交互文章链接
重点文章: 1.[Unity3D]Unity3D游戏开发之Lua与游戏的不解之缘(上) 2.[Unity3D]Unity3D游戏开发之Lua与游戏的不解之缘(中) 3.Lua和C++交互详细总结 4. ...
- lua脚本之lua语言简介以及lua的安装
本博主不擅于进行文字创作,所以,相当一部分文字皆复制于其他博文.还希望能够得到谅解. 一.Lua语言简介 Lua是一个免费的开源软件,可以免费用于科研及商业.Lua具有一个专家团队在维护和升级,其设 ...
- 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””] ...
- 【Lua】linux下lua+mod_lwt环境搭建
Lua 是一个小巧的脚本语言.它具有轻量级.可扩展等优势.它可以作为一个强大.轻量的脚本语言,供任何需要的程序使用. LWT (Lua Web Tools) 可让你使用 Lua 开发 Web 应用,并 ...
- [Lua快速了解一下]Lua运行
-Lua的Hello World print("Hello World") 分号可选 -类似python,进入Lua后再shell中打命令执行语句也可 > print(&qu ...
随机推荐
- nopCommerce_3.00-Nop.Core.Caching
namespace Nop.Core.Caching { /// <summary> /// Cache manager interface /// </summary> pu ...
- word模版另存为网页(*.htm,*.html),转为jsp页面并加入数据后导出成word
word模版另存为网页之后,将html格式的文件转为jsp页面,在页面上加入相应的动态值,加入的值中包含图片,这个该怎么处理??另外导出的文件需要拷贝到不同的地方(无法联网)使用. <%@ pa ...
- Peterson算法与Dekker算法解析
进来Bear正在学习巩固并行的基础知识,所以写下这篇基础的有关并行算法的文章. 在讲述两个算法之前,需要明确一些概念性的问题, Race Condition(竞争条件),Situations lik ...
- find job
处于找工作的状态... 优秀求职者的5个问题: 1.在刚进来2-3个月里,你希望我可以完成哪些工作? 2.公司的优秀员工共同特征是什么? 3.业余时间,公司的员工一般在干什么?
- KVM地址翻译流程及EPT页表的建立过程
本博文为原创,遵循CC3.0协议,转载请注明出处:http://blog.csdn.net/lux_veritas/article/details/9284635 ------------------ ...
- JVM经常使用的调优參数
-Xms512m -Xmx1024m -XX:MaxPermSize=1204m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+ ...
- linux-0.11内核 调试教程+GCC源代码
http://pan.baidu.com/share/home?uk=453348606&view=share#category/type=0 http://blog.csdn.net/old ...
- windows修改mysql默认字符集不成功
今天下午弄了半天,终于把mysql的默认字符集弄成了, 按照网上的说法,什么修改mysql下面的my.ini文件,把参数设置成utf-8,我反复操作,结果都是不成功,后来我把mysql5.0卸载了,网 ...
- Chapter 6 - How to Play Music and Sound Effect
In this chapter, we would add background music to the game and play sound effect when the hero fires ...
- Spring XD 1.1 M2 and 1.0.3 released---support kafka
官方地址:http://spring.io/blog/2014/12/23/spring-xd-1-1-m2-and-1-0-3-released On behalf of the Spring XD ...