免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: Perlvim
打印 上一主题 下一主题

{Lua}语言版块 [复制链接]

论坛徽章:
7
戌狗
日期:2013-12-15 20:43:38技术图书徽章
日期:2014-03-05 01:33:12技术图书徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16赛季CBA联赛之青岛
日期:2016-03-17 20:36:13
11 [报告]
发表于 2012-11-30 06:27 |只看该作者
moonscript 简洁比 lua

论坛徽章:
0
12 [报告]
发表于 2012-11-30 10:59 |只看该作者
撸啊{:2_168:}

论坛徽章:
0
13 [报告]
发表于 2012-12-07 12:41 |只看该作者
Hello all,
I am a new user of Lua, I want to learn Lua.

I found the newest version is 5.2.1, the newest version of windows installer is 5.1.4.

I found it have great change from 5.1.4 to 5.2.1. LuaJIT is a faster interpreter of LUA, but it only support 5.1.x.

I want to know LuaJIT would became an individual version of Lua or would upgrade and support to 5.2.1?

I am afraid MoonScript also could became an different language.

The declaration word of function is too long, If it would be shorter?
default variable declaration is global, but local variable is more faster, Why Lua use global variable as default declaration?

If have any observed word would be used as keyword of Lua in furture?

following code could not run yesterday, but it is worked before

local filename = 'perlvim.lua'
local fh = io.open(filename, 'r')
local text = io.read("*all")
print(text)

If have any same question occured someone else?

论坛徽章:
78
双子座
日期:2013-10-15 08:50:09天秤座
日期:2013-10-16 18:02:08白羊座
日期:2013-10-18 13:35:33天蝎座
日期:2013-10-18 13:37:06狮子座
日期:2013-10-18 13:40:31双子座
日期:2013-10-22 13:58:42戌狗
日期:2013-10-22 18:50:04CU十二周年纪念徽章
日期:2013-10-24 15:41:34巨蟹座
日期:2013-10-24 17:14:56处女座
日期:2013-10-24 17:15:30双子座
日期:2013-10-25 13:49:39午马
日期:2013-10-28 15:02:15
14 [报告]
发表于 2012-12-07 13:12 |只看该作者
回复 13# Perlvim


    c版有人熟悉lua,你可以@他们

http://bbs.chinaunix.net/thread-4054291-1-2.html

论坛徽章:
7
巳蛇
日期:2014-04-10 08:54:57白羊座
日期:2014-04-22 20:06:262015年亚洲杯之沙特阿拉伯
日期:2015-02-10 14:18:532015年辞旧岁徽章
日期:2015-03-03 16:54:152015亚冠之吉达阿赫利
日期:2015-06-02 11:34:112015亚冠之武里南联
日期:2015-06-24 12:13:082015亚冠之阿尔纳斯尔
日期:2015-08-03 09:08:25
15 [报告]
发表于 2012-12-07 15:09 |只看该作者
Perlvim 发表于 2012-12-07 12:41
default variable declaration is global, but local variable is more faster, Why Lua use global variable as default declaration?

following code could not run yesterday, but it is worked before

local filename = 'perlvim.lua'
local fh = io.open(filename, 'r')
local text = io.read("*all")
print(text)

Don't know what you mean by saying Lua use global variable as default declaration. It's a good practise to declare variables before using them, and when declaring them you should use local as most as you can.

Only you can use a variable before you declare them in lua, which makes it a global variable with a nil value, which is not desired at the most cases and should be avoided.

And one thing, assign a value to a variable is not the same as declare a variable. AFAIK, Lua only have one keyword for declare variables, which is 'local'.

Maybe you were thinking about something like following which works for me(Pay attention to the third line):

  1. local filename = 'perlvim.lua'
  2. local fh = io.open(filename, 'r')
  3. local text = fh:read("*all")
  4. print(text)
复制代码

论坛徽章:
0
16 [报告]
发表于 2012-12-08 09:12 |只看该作者
yes, filehand:read is ok.

In moonscript, all the variable would be transfered to local

MoonScript:
for key, value in pairs(my_table) do
    -- do something
end

--> will transfer to
local key, value
for key, value in pairs(my_table) do
    --- do something
end

If We want use a global variable. how to declare it?

just like:
global var = 'stirng'

I think MoonScript should add a keyword to declare global variable, like 'our', 'var', or 'global' .. etc

我的意思是 关键字定义的问题:
定义一个函数的关键字是 function, 这个太长了,频繁使用的关键字应当短一些。
ruby, python 是 def, Perl 是 sub, Moonscript & CoffeeScript 用 -> 来做函数的声明字符。



论坛徽章:
0
17 [报告]
发表于 2012-12-08 09:27 |只看该作者
在以下情形下,变量是局部的

1. 函数的参数声明是局部的 -> arg
function function_name(args)
    -- some expression
end

2. 循环的迭代参数 key, value
for key, value in pairs(my_table) do
    -- do something
endf

论坛徽章:
0
18 [报告]
发表于 2012-12-08 14:38 |只看该作者
-- lua 不能处理 unicode 字符
-- lua 只能处理 1-255范围内的ASC字符

string.char(256) 会报错。

论坛徽章:
0
19 [报告]
发表于 2012-12-08 14:56 |只看该作者
如何测试某个单词是Lua的关键字呢?

Lua 5.2.1增加了 goto 作为关键字,如何用一个脚本来测试这个变化呢?

论坛徽章:
0
20 [报告]
发表于 2012-12-09 17:03 |只看该作者
想让你的程序的性能达到极致吗?请学习C语言吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP