lua支持中文--改法修正



看到网上各种转载修改源码使lua支持中文的,结果试了下发现测试出来有问题,如:
 >function 为而的() end
 stdin:1: '(' expected near ')'
这里就会报错,只好改下,就没问题了,如下改后的源码(改动之处已标明,lua5.1/lua5.2/lua5.3均支持)。


</pre><pre name="code" class="javascript">
#pragma once

#include <ctype.h>

//
//
//这是中文函数名添加的函数
//
/*开始添加支持中英文变量名*/
/*因为LS->current是int类型!*/


#define USE_CHINESE_NAME   
#ifdef USE_CHINESE_NAME   
#define isChineseCode(charint)   (charint >= 0x80)		//<<<<<<<<<<<<<<<<<< 第一处
#define readxxname(ls) readChinesename(ls)   
void readChinesename(LexState *ls)
{
	do
	{
		if (isChineseCode(ls->current))
		{
			save_and_next(ls);
			//if(ls->current!='(')
			if(isChineseCode(ls->current))		//<<<<<<<<<<<<<<<<<<< 第二处
			{
				save_and_next(ls); //处理了一个中文字符   
			}
		}
		else
		{
			//if(ls->current!='(')
			{
				save_and_next(ls); //处理英文字符或者下划线   
			}
		}
	} while (isChineseCode(ls->current) || ls->current == '_' || isalnum(ls->current));
}
#else   
#define isChineseCode(charint) 0   
#define readxxname(ls) readname(ls)   
void readname(LexState *ls)
{
	do
	{
		save_and_next(ls); //处理英文字符或者下划线   
	} while (isChineseCode(ls->current) || ls->current == '_' || isalnum(ls->current));
}
#endif  


//
//
//以上是中文变量名定义函数
//
//


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值