闲来的时候做了个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 ...
我们在编写lua模块的时候经常会遇到申请内存的情况,有2中用途 1。 临时的 2. 长期的。 通常我们是用malloc来分配内存 free来释放。但是这样做的话 lua runtime就没有办法跟踪内存的使用。但是我们有解决方法:
1. 临时的 通过LuaL_Buffer来, 因为LuaL_buffer有自主扩展能力,所以我们可以存入很多数据 只是每次可以直接使用buffer的大小有限制。
2. 长期的, 通过lua_newuserdata 放在fenv里面. fenv 是个table,而且可以gc. 当分配的内存不够用的时候 可以重新分配一个 然后lua_replace一下 这样旧的内存就会 ...
参见: 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 ...
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 ...
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 ...
当要用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;
...
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 ...
copas是纯lua的实现 依赖于luasocket, 但是毕竟大的现在,只能支持1024个并发,是select机制的限制。
luaevent和copas的接口很像,基于libevent,支持epoll等,可以支持大规模的并发。
copas经过几天几夜的测试, 比较稳定,但是吃比较多的内存。
luaevent测试在进行中。
注:
在copas或者luaevent.loop 中加入
print(collectgarbage("count")) 可以知道lua vm用的内存 以K为单位。
原型: 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 还是其他东西。
总之设计还是很巧妙的。
一直对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行)接受用户输入 ...
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 ...
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 ...
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 ...
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 ...
- 浏览: 71936 次
- 性别:

- 来自: 广州

- 详细资料
搜索本博客
最近加入圈子
链接
最新评论
-
tail程序 c版本和lua版本 ...
不错,有点意思,支持一下楼主
-- by liuming -
tail程序 c版本和lua版本 ...
[root@test98 haproxy]# ls -lh /var/log/h ...
-- by mryufeng -
tail程序 c版本和lua版本 ...
把/var/log/haproxy.log拷三份来测比较准吧
-- by Sam1860 -
tail程序 c版本和lua版本 ...
算法基本一样, lua重复利用现有的c native 实现, c程序大概是lua ...
-- by mryufeng -
tail程序 c版本和lua版本 ...
你俩个算法都不一样比较啥啊?
-- by makefile






评论排行榜