`
sillycat
  • 浏览: 2566539 次
  • 性别: 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/


分享到:
评论

相关推荐

    Program in LUA 2nd Edition.rar

    1 Getting Started 3 1.1 Chunks 4 1.2 Some Lexical Conventions 5 1.3 Global Variables 6 1.4 The Stand-Alone Interpreter 7 2 Types and Values 9 2.1 Nil 10 2.2 Booleans 10 2.3 Numbers 10 2.4 ...

    Programming in LUA

    ##### 开始入门 (Getting Started) - **环境和代码块**:在Lua中,程序通常由一系列独立的代码块组成,这些代码块可以是函数、库或者其他自包含的代码片段。环境设置包括运行时环境和加载路径配置等。 - **一些词法...

    Redis-Essentials.pdf

    Chapter 1, Getting Started (The Baby Steps), shows you how to install Redis and how to use redis-cli, the default Redis command-line interface. It also shows you how to install Node.js and goes ...

Global site tag (gtag.js) - Google Analytics