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 do
local char = string.sub(str, i, i)
has_process = false
if previous_is_number == false and (string.find(char, "%a") or string.find(char, "_")
or (string.find(char, "%d") and previous_is_string) )
then
stringbuffer = string.format("%s%s", stringbuffer, char)
previous_is_string = true
has_process = true
end
if not (previous_is_number and char == ".") and (has_process == false and string.find(char, "%p")) then
if stringbuffer ~= "" then
table.insert(tokens, stringbuffer)
stringbuffer = ""
previous_is_string = false
end
if numberbuffer ~= "" then
table.insert(tokens, numberbuffer)
numberbuffer = ""
previous_is_number = false
is_X16mode = false
end
table.insert(tokens, char)
previous_is_quote = true
has_process = true
end
if has_process == false and ((string.find(char, "%d") or (numberbuffer ~= "" and string.find(char, "%.")))
or (is_X16mode and string.find(char, "%x")) ) then
if (previous_is_number == false) then
local nextchar = string.sub(str, i+1, i+1)
if nextchar and (nextchar == "x" or nextchar == "X") then
is_X16mode = true
i = i+1
char = char .. nextchar
end
end
numberbuffer = string.format("%s%s", numberbuffer, char)
previous_is_number = true
has_process = true
end
end
print_table(tokens)
return tokens
end
--local str = [[dequeOf.use("1155.321"). STRINGI.push_back(CComVariant("{"));]]
--local str = [[if ((vtVal.vt != VT_I4) || (0x0000FFFF<(DWORD)vtVal.lVal))]]
--local str = [[333, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D};]]
--get_tokens(str)
分享到:
- 2009-09-25 10:15
- 浏览 1298
- 评论(0)
- 论坛回复 / 浏览 (0 / 1611)
- 查看更多
相关推荐
关于tolua++的资料太少,这个通过实例让你知道如何通过tolua++和C++交互,简单明了。 通过5个文件来演示这个tolua++版 hello world hello.lua ,hello.h ,hello.pkg ,Main.cpp ,build_pgk.bat 1.启动CodeBlocks...
能运行js-lua-c++代码的sublime解压直接使用 sublime里更改编译系统能直接运行 lua js c++代码 用来测试 这3种语言的 语法 很方便!!!!!!
C++调用Lua函数 以及Lua调用C++函数
NULL 博文链接:https://pirateyk.iteye.com/blog/513811
本人亲自编译通过的程序,如果无法通过只可能是您的编译环境有问题。本人的开发环境:VC++6.0,使用的是Win32 Console Application
基本的调用lua变量与函数,实现文本的获取与显示策略,若要改变显示方式,只要修改move()函数即可.
lua调用c++函数的实例,C++工程里使用LUA脚本,lua脚本调用c++工程的函数
实现LUA中调用C++类,并对其封装, LINUX下编译
c++ lua 框架资源包c++ lua 框架资源包c++ lua 框架资源包c++ lua 框架资源包c++ lua 框架资源包c++ lua 框架资源包c++ lua 框架资源包c++ lua 框架资源包c++ lua 框架资源包c++ lua 框架资源包c++ lua 框架资源包...
介绍lua调用c++动态库的简单步骤,内容包括c++动态库的创建和lua中代码调用DLL
简单实用的c++调用lua 的源代码案例
lua 调用 c++ dll 示例 vs2010 编写的,这个例子很简单哦!
lua解析器,方便lua开发
c++调用lua脚本程序代码,工程为vs2013直接打开直接用。csdn博客上有详细的学习步骤和解析,这里的是开发学习过程的所有源代码和项目文件
这是将 Lua游戏开发技术书中剪接出来的一个Lua脚本与C++交互的游戏。 主要是精简,代码突出,思路清晰,很容易看懂Lua和C++的交互流程。 入门级别的完整代码。 vs2010工具打开不用转换。
文档详细的介绍了,lua 如何去绑定c++ 访问到c++ 代码
cocos2d-x-3.10 player3 手游开发 lua 绑定 c++ lua调用c++类
在LUA中实现PROTOBUF的功能。该功能依赖于部分C码。本工程对这一过程做了简单的示例。
1、支持访问包或表里的函数 2、支持任意数量的参数和返回值 3、支持INT,STRING,TABLE三种参数,返回值类型 4、TABLE支持多层表的嵌套。
很适合初学者学习,这是一个Lua和C++交互的一个简单例子,简单明了,容易理解