`
sillycat
  • 浏览: 2551850 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Programming in Lua(1)Getting Started

 
阅读更多
Programming in Lua(1)Getting Started

1. Getting Started
I can run my first hello world application with command line
>lua hello.lua
print("hello, carl")

Another example just like the C programme
function fact(n)
if n==0 then
  return 1
else
  return n*fact(n-1)
end
end

print("enter a number:")
a = io.read("*number")
print(fact(a))

1.1. Chunks
A chunk is simply a sequence of statements.
Semiclolons separate two or more statements, but this is just a convention.

We can aslo type the command >lua to enter the interactive mode, ctrl + c to exit.

The first way to link a chunk
>lua -la -lb
a means a.lua file, and b means b.lua file.

The second way to link a chunk
--file 'lib1.lua', I put the fact(n) function in that lib file.
D:\work\lua>lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> dofile("lib1.lua")
> n = fact(3)
> print(n)

1.2. Global Variables
print(b) ----> nil
b=10
print(b) ----->10

1.3. Some Lexical Conventions
The following words are reserved; we cannot use them as identifiers:
and  break do else ...

Lua is case-sensitive: and is a serverd word, but And and AND are two other identifiers.

A comment starts anywhere with
A double hyphen(--).
Block comments with --[[ ]]--.

print("test------") --test
--[[
  test for fun
  ]]--
print("test end --")

1.4. The Stand-Alone Interpreter
..snip..

references:
http://www.lua.org/pil/


分享到:
评论

相关推荐

    Programming in Lua Fourth edition

    《Programming in Lua Fourth Edition》是关于Lua编程语言的一本权威指南,由Luiz Henrique de Figueiredo、Ricardo Tomasi和Tiago Fonseca共同撰写。这本书详细介绍了Lua语言的核心概念、语法和特性,是学习和精通...

    Programming in Lua(中文版).pdf

    《Programming in Lua》是一本专为学习和精通Lua编程语言而编写的权威指南。这本书的中文版提供了对Lua语言深入且全面的解析,适合初学者和有经验的程序员使用。Lua是一种轻量级、高性能、易扩展的脚本语言,广泛...

    Programming in Lua(4th) 无水印pdf

    Programming in Lua(4th) 英文无水印pdf 第4版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传...

    Programming In Lua 中文版PDF高清

    ### Programming In Lua 知识点概览 #### 第一篇 语言 **第0章 序言** - **简述**:介绍了《Programming in Lua》这本书的目的、适用对象以及为何选择Lua作为学习对象等内容。 - **知识点**:了解Lua语言的特点...

    Programming in Lua, 3rd.pdf

    Programming in Lua, 3rd.pdfProgramming in Lua, 3rd.pdfProgramming in Lua, 3rd.pdfProgramming in Lua, 3rd.pdf

    Programming in Lua 4th Edition 高清版 带完整书签

    《Programming in Lua 4th Edition》是一本专为学习和精通Lua编程语言而编写的权威指南。这本书由 Lua 的主要开发者之一,Pedro Melo 执笔,旨在深入浅出地介绍Lua语言的核心概念、语法和应用。第四版是该系列的最新...

    programming in lua_lua_

    《Programming in Lua》是关于Lua编程语言的一本权威书籍,由巴西计算机科学家Pietro Trovato撰写。这本书深入浅出地介绍了Lua语言的核心概念、语法特性以及在实际开发中的应用。Lua是一种轻量级、高效且可扩展的...

    Programming in Lua(2nd Edition)

    《Programming in Lua》第二版是一本介绍Lua编程语言的经典著作,由Roberto Ierusalimschy撰写,是深入了解和学习Lua语言的宝贵资源。Lua是一种轻量级的、高效、易于嵌入的脚本语言,广泛应用于游戏、移动应用、网络...

    LUA编程programminginlua.rar

    "Programming in Lua"是一本广泛认可的LUA编程教程,由Pierre Giraud编写,深入浅出地介绍了LUA语言的核心概念和技术。这个压缩包"LUA编程programminginlua.rar"包含了学习LUA编程的重要资源。 打开"Programming in...

    Programming in Lua Second Edition

    《Programming in Lua Second Edition》是关于Lua编程语言的一本经典著作,主要针对的是Lua 5.1版本。这本书深入浅出地介绍了Lua语言的核心概念、语法特性以及在实际开发中的应用,是学习和掌握Lua语言的重要参考...

    Programming in Lua 3rd(mobi)

    不多说,学习Lua必备,Roberto Ierusalimschy大作,英文版,mobi格式,供kindle人学习使用。

    ProgramminginLua中文版

    ProgramminginLua中文版 介绍Lua语法 适用于wow插件开发

    Programming In Lua

    Programming in Lua provides a solid base to any programmer who wants to use Lua. It covers all aspects of Lua—from the basics to its API with C. The book is the main source of programming patterns ...

Global site tag (gtag.js) - Google Analytics