2008-08-10

tail程序 c版本和lua版本大比拼

关键字: lua c 性能 比较
闲来的时候做了个tail 程序,和*nix下的tail功能一样 Usage: ./tail -n nnnn filename lua版本代码 20行, c版本代码173行,开发速度大概差5倍。 代码效率: time tail -n 1000000 /var/log/haproxy.log >/dev/null 从log文件尾巴中抽取1000000行。 1.linux 版本的tail: real 0m0.330s user 0m0.172s sys 0m0.156s 2. c版本的tail: real 0m0.398s user 0m0.156s sys ...
2008-07-25

lua扩展模块里面如何申请内存

关键字: lual_buffer lua_newuserdata
我们在编写lua模块的时候经常会遇到申请内存的情况,有2中用途 1。 临时的 2. 长期的。 通常我们是用malloc来分配内存 free来释放。但是这样做的话 lua runtime就没有办法跟踪内存的使用。但是我们有解决方法: 1. 临时的 通过LuaL_Buffer来, 因为LuaL_buffer有自主扩展能力,所以我们可以存入很多数据 只是每次可以直接使用buffer的大小有限制。 2. 长期的, 通过lua_newuserdata 放在fenv里面. fenv 是个table,而且可以gc. 当分配的内存不够用的时候 可以重新分配一个 然后lua_replace一下 这样旧的内存就会 ...
2008-07-23

未公开的Lua Frontier Pattern %f 比较实用

关键字: frontier pattern %f
参见: http://lua-users.org/wiki/FrontierPattern Frontier Pattern lua-users home wiki The "frontier" expression pattern %f is undocumented in the standard Lua references (for reasons why see LuaList:2006-12/msg00536.html). I would like to present here the usefulness of it, in an attempt to show h ...
2008-07-22

Notes about how the Lua garbage collector works

关键字: lua lua garbage collector gc
lua垃圾收集的原理 参见: http://lua-users.org/wiki/EmergencyGarbageCollector Notes about how the Lua garbage collector works Disclaimer: This is the first time I have worked on a garbage collector so some of this may be incorrect. Corrections/cleanups are welcome. --RobertGabrielJakabosky "While working on ...
2008-07-21

Yueliang + LuLu 完整的LuaInLua系统

关键字: yueliang lulu
Yueliang: http://yueliang.luaforge.net/ Introduction The goal of Yueliang is to implement Lua 5 in Lua 5. Such a codebase, if well documented, can be a useful prototyping and educational tool. Initially, the focus is on the front end of Lua, i.e. the lexical analyzer, the parser and the code gener ...
2008-07-18

luatcc 方便你写lua扩展

关键字: luatcc
当要用c实现lua的模块的时候 就涉及到模块的编译 调试 运行 而这些步骤很繁琐,容易出错,有了luatcc就可以直接在lua代码里面直接写c代码了 动态运行 岂不是很cool, 大大提高了开发速度。 luatcc项目网站: http://luaforge.net/projects/lua-tcc/ require "lua_tcc" m = tcc.compile ([[ #include "lua.h" typedef struct { void *s; } tcc_userdata; ...
2008-07-04

luacoco 增强lua的coroutine功能

关键字: luacoco coroutine
Coco is a small extension to get True C Coroutine semantics for Lua 5.1. Coco is both available as a stand-alone release and integrated into LuaJIT. The stand-alone release is a patchset against the standard Lua 5.1.3 distribution. There are no dependencies on LuaJIT. However LuaJIT depends on Coc ...
2008-07-04

lua做tcp服务器的2套库

关键字: lua tcp luaevent copas
copas是纯lua的实现 依赖于luasocket, 但是毕竟大的现在,只能支持1024个并发,是select机制的限制。 luaevent和copas的接口很像,基于libevent,支持epoll等,可以支持大规模的并发。 copas经过几天几夜的测试, 比较稳定,但是吃比较多的内存。 luaevent测试在进行中。 注: 在copas或者luaevent.loop 中加入 print(collectgarbage("count")) 可以知道lua vm用的内存 以K为单位。
2008-07-04

lua symbexec的2个用途

关键字: lua symbexec luag_checkcode
原型: static Instruction symbexec (const Proto *pt, int lastpc, int reg); symbexec 是安装vm的执行流程来模拟一段opcode的执行, 执行到lastpc, 同时返回修改reg的那条指令。 有2个用途 1. loadstring检查代码是否被篡改,是否合法 2. 用于lua_getinfo的时候 看一个first class的function是global,local,upval 还是其他东西。 总之设计还是很巧妙的。
2008-07-03

lua coroutine是如何实现的?

关键字: lua coroutine
一直对coroutine的运作原理不是很明白, 这几天琢磨了下终于搞明白了: root@yfnix:~/lua-5.1.3/src# cat t.lua a= coroutine.create(function () b= coroutine.create(function () coroutine.yield(1) end) coroutine.resume(b) end) coroutine.resume(a,1) root@yfnix:~/lua-5.1.3/src# gdb --args lu ...
RemDebug is a remote debugger for Lua 5.0 and 5.1. It lets you control the execution of another Lua program remotely, setting breakpoints and inspecting the current state of the program. RemDebug can also debug CGILua scripts. 看他的源码只有2个东西:controller.lua 和 remdebug/engine.lua controller(233行)接受用户输入 ...
2008-06-30

Lua For Windows v5.1.3.11 Release Candidate 1

关键字: lua scite 编辑 调试
Lua For Windows v5.1.3.11 Release Candidate 1 Andrew Wilson - 2008-06-28 00:19 - Lua for Windows We are proud to announce the first release candidate of Lua for Windows (LfW). This moves this project into feature freeze, so only bugs will be fixed until the official release. Let us know what ...
2008-06-27

Alien - Pure Lua extensions

关键字: alien lua
What is Alien Alien is a Foreign Function Interface (FFI) for Lua. An FFI lets you call functions in dynamic libraries (.so, .dylib, .dll, etc.) from Lua code without having to write, compile and link a C binding from the library to Lua. In other words, it lets you write extensions that call out to ...
Announcing LuaEdit 2008 and new website Jean-François Goulet - 2008-06-24 21:14 - LuaEdit LuaEdit is getting a whole new look with the upcoming version of LuaEdit 2008 which will support the latest version of Lua 5.1, remote debugging, easy software integration and solution oriented manageme ...
2008-06-27

lua newproxy用途

关键字: newproxy
What does newproxy() in 5.1? > I find newproxy a curious addition. It gives you unique userdata that > share the same metatable. I cannot think of a use for it yet. > What did you have in mind? This is a very experimental feature. We wanted a simple and secure way of creating userdata in Lua. It ...
2008-06-26

你们有yum 我有LuaRocks

关键字: luarocks
LuaRocks This is LuaRocks, a deployment and management system for Lua modules. LuaRocks allows you to install Lua modules as self-contained packages called "rocks", which also contain version dependency information. This information is used both at install time, so that when one rock is requested ...
Introduction LPeg is a new pattern-matching library for Lua, based on Parsing Expression Grammars (PEGs). In this text, I assume you are familiar with PEGs. If you are not, you can get a quick start reading the Wikipedia Entry for PEGs or Section 2 of Parsing Expression Grammars: A Recognition-Base ...