2009 年文章归档
共 28 篇文章
lua string trim
function trim(s) local from = s:match"^%s*()" return from > #s and "" or s:match(".*%S", from) end
2009-12-27 16:26
API design tips
API Design Tips "It's very easy to create a bad API and rather difficult to create a good one." - Michi Henning, API Design Matters , Communications of the ACM Vol. 52 No. 5 First think of the consumer of the API. Think about his likely situation and the problems he's facing. He doesn't want to lea…
2009-12-24 12:33
进程间通讯demo
// 使用Memory Mapping file共享数据,使用一个Event作为并发控制。 // 仅为练习使用。 #define BUFFER_SIZE (100*1024) #define BUFSIZE 1024 struct BufferStruct { BOOL hasRead; TCHAR buf[512]; }; void CEDSInstallMain1Dlg::OnBnClickedButton1() { TCHAR szMapFileName[] = _T("Local\\TestHelloWorld"); // Create the file mapping object…
2009-12-23 14:56
[msdn] Interprocess Communications
The Windows operating system provides mechanisms for facilitating communications and data sharing between applications. Collectively, the activities enabled by these mechanisms are called interprocess communications (IPC). Some forms of IPC facilitate the division of labor among several specialized…
2009-12-23 08:35
[MSDN] Named Pipe Server Using Overlapped I/O
The following is an example of a single-threaded pipe server that uses overlapped operations to service simultaneous connections to multiple pipe clients. The pipe server creates a fixed number of pipe instances. Each pipe instance can be connected to a separate pipe client. When a pipe client has …
2009-12-23 08:31
Lua 调用ClearTool获取某文件最新的注释内容
local cmdStr= [[cleartool describe -fmt "%c" "D:\DEV_FEATURE\wei\test1.cpp"]] local f = assert(io.popen(cmdStr)) local str = assert(f:read('*a')) f:close() print(str)
2009-12-04 10:19
一个自动更新VC++项目版本号的Lua脚本
某个项目经常需要在改完代码之后修改版本号,大概有7、8个文件需要一个个改动然后check in。我发现这个操作有个特点就是所有的版本号都是一样的,而且需要修改的字符串非常有规律,就是类似查找1, 6, 0, 16替换成1, 6, 0, 17这样,同时还有1,6,0,16替换成1,6,0,17(区别是逗号后面没有空格)。这种分析查找替换用Lua来做再简单不过了,故此写了这个脚本。 如果要使用的话,需要修改下面粗体部分,comment_string是将被作为注释加入clearcase的。old_string和new_string分别是当前版本号以及下一个版本号。projfolder一般只需要修改…
2009-11-27 08:36
How to create c extension for lua and pass complex structure step by step
Original link: http://sunxiunan.com/?p=1498 You could download the project from http://groups.google.com/group/lua5/web/luautil.rar At first, create a windows dll application. The IDE I used is VC2008. I suggest you download and install the " Lua for windows " from luaforge.net, it contains most us…
2009-11-24 11:00
Change Ugly code in our project
following code happens many times in our project: xxxxxxx; #if defined _ETHERNET tmp1String = deviceKey.GetAddressAsString(); #else tmp1String = deviceKey.GetNodeAsString(); #endif yyyyyyy; It should be changed like: CString GetAddrString(DeviceKey& deviceKey) { CString tmp1String; #if defined _ETH…
2009-11-23 17:48
Lua runtime code reading Lua运行期源代码分析阅读
http://sunxiunan.com/?p=1477 You could download the project for VC2008 in http://groups.google.com/group/lua5/web/lua_vc2008.rar The project will use parameter like "c:\test.lua", and the lua script like above image. The code starting point is pmain(). lua parser will parse the code file, and use L…
2009-11-19 13:25
Google的Go编程语言使用初探
http://sunxiunan.com/?p=1463 Go编程语言是Google中一些大牛(尤其是有着plan9前科的大牛们)如Rob Pike,Ken Thomason这两位赫赫有名的程序高手、技术作家。 很多人认为Go编程语言有点像是C语言与Python的混血,在Golang主页上也清楚写着Go的祖先有C,有Pascal/Modula(也是C++的祖先)/Oberon,还有CSP这个语言,另外很多基础代码也来自Plan 9操作系统。 我是在一个Ubuntu9.10的虚拟机上试用的Go,大家可以跟着我的脚步一探Go的究竟。 1,准备 安装Go之前需要安装mercurial,这是Go的版…
2009-11-12 19:00
勿用屠龙来杀猪-论如何正确整合Lua与C++
http://sunxiunan.com/?p=1447 经常有人问到关于Lua的问题是“Lua如何能使用C++的成员变量?”“Lua如何调用C++类的成员函数?”“C++的复杂数据结构(如数组)如何传递进入Lua让Lua可以使用?” 这些问题之频繁,几乎每天都可以看到。问题的起源也很简单,这些提问者大多是C++程序员,公司需要使用Lua,他们就想如何能够“完美无缝”整合C++和Lua。 如果在谷歌中文(google.cn)搜索Lua关键字,第一页大概前五六个网址中会有云风的这篇文字《 Lua 不是 C++ 》,里面的结论部分十分精彩: 对于那些新接触 lua 的 C/C++ 程序员来说,我…
2009-11-09 12:41
谷歌拼音输入法支持lua编写api
lua利好消息,google拼音加入支持lua。 下载最新版本的谷歌拼音,就可以通过lua来扩展它的功能了。 api的帮助信息在这里能看到 http://www.google.com/ime/pinyin/api.html 安装完以后,在 c:\Documents and Settings\All Users\Application Data\Google\Google Pinyin 2\Extensions 可以找到一个base.lua,里面代码写的比较清楚了。 比如这个计算模式。 function Compute(input) local expr = "return " .. _Add…
2009-10-29 13:03
Lua code reading
Online Lua 5.1 source code browser Recommended reading order: lmathlib.c, lstrlib.c: get familiar with the external C API. Don't bother with the pattern matcher though. Just the easy functions. lapi.c: Check how the API is implemented internally. Only skim this to get a feeling for the code. Cross-…
2009-10-16 14:42
使用ironruby播放twitter的timeline
require "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" require "System.Speech, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" require "System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" wc = System::Net::WebClient.new cont…
2009-10-15 17:29
如果我来做软件(2)- You ain’t gonna need it
http://sunxiunan.com/?p=1333 闲逛javaeye论坛,发现一个很有趣的帖子《 面子驱动编程 》,里面的观点简单说就是:从客户需求出发,实事求是,面向用户(或者说面向需求)来做设计。 前面我写了一篇文字 如果我来做软件(1)- 评《走出软件作坊》 ,这里想写的是软件开发最重要的一个时期,也就是所谓的 需求分析阶段 。 在维基百科上是这样解释需求分析的: 在 软件工程 中, 需求分析 指的是在建立一个新的或改变一个现存的 电脑系统 时描写新系统的目的、范围、定义和功能时所要做的所有的工作。需求分析是软件工程中的一个关键过程。在这个过程中,系统分析员和软件工程师确定顾客…
2009-10-13 17:22
Lua 解析C++代码tokens简单函数
function get_tokens(str) local string = string local table = table local tokens = {} local stringbuffer = "" local numberbuffer = "" local previous_is_number = false local previous_is_string = false local previous_is_quote = false local has_process = false local is_X16mode = false for i = 1, #str d…
2009-09-25 10:15
简单的迅雷链接转换工具
http://bbs.luaer.cn/read-Lua-tid-861.html -------------------------------------------------- require ("wx") -- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss < alexthkloss@web.de > -- licensed under the terms of the LGPL2 -- character table string local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs…
2009-09-17 09:11
MonoDevelop for windows
Installer for Windows - Unstable To run MonoDevelop on Windows you have to download and run the following installers: .NET Framework 3.5 (You may already have this installed) Download GTK# for .NET 2.12.9-2 (if you have older versions installed, please uninstall first) Download MonoDevelop 2.2 Beta…
2009-09-16 08:41
Lua调用微软DotNet framework
-- http://penlight.luaforge.net/packages/LuaInterface/ require "CLRPackage" import "System.Threading" import "System.Console" import "System.Math" import "System.Timers" -- http://msdn.microsoft.com/zh-cn/library/system.math.aspx Console.WriteLine("Sqrt(99) " .. Math.Sqrt(99)) Console.WriteLine("Lo…
2009-09-09 17:47