分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
官网地址:http://www.inf.puc-rio.br/~roberto/lpeg/
LPeg是一个为Lua所使用的新的模式匹配库,基于解析表达式语法(PEGs)。
1.新建“Win32 Console Application”工程,工程名为:lpeg
2.在“Application Settings”中,选择“DLL”和“Empty project”
3.添加下载的“lpeg.h”、“lpeg.c”到工程中
4.菜单栏→“Project”→“Properties”,配置“All Configurations”,"Additional Include Directories"添加"...\Lua\5.1\include","Additional Library Directories"添加"...\Lua\5.1\lib","Additional Dependencies"添加"lua5.1.lib"
5.菜单栏→“Project”→“Add New Item”→“Modele-Definition File(.def)”,名称为:lpeg
6.“lpeg.def”的内容为:
1
2 |
LIBRARY "lpeg"
EXPORTS luaopen_lpeg |
8.测试使用,新建一个lua脚本,内容为:
1
2 3 4 5 6 7 8 |
local lpeg = require "lpeg"
-- matches a word followed by end-of-string p = lpeg.R "az"^ 1 * - 1 print(p:match( "hello")) --> 6 print(lpeg.match(p, "hello")) --> 6 print(p:match( "1 hello")) --> nil |
![](https://img-my.csdn.net/uploads/201210/08/1349695300_7494.png)
Simple Matching 简单匹配
1
2 3 4 5 6 7 8 9 |