zoukankan      html  css  js  c++  java
  • lua快速入门

    1、开发环境

        去网上下载一个 Lua for Windows

          下载地址: http://luaforge.net/projects/luaforwindows/  

    2、lua扩展名 .lua

    3、快速入门

        1、helloworld

    print "hello world"
    print("hello world") --注释

       多行注释

    --[[
    for i= 1, 7,1 do
        print(revdays[i])
    end
    --]]

       2、数据类型:   nil、  Booleans、 Numbers 、Strings、functions

       3、表达式:

           算数运算 : + – * / –(一元运算)

           关系运算 : < > <=  >= ==  ~=

           逻辑运算 : and or not

           连接运算符: .. --两个点

    print("hello".."jack")

           优先级 

           表的构造

    days = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}
    print(days[5])

         4、基本语法:

              赋值语句

    a  = "hello".."world" --赋值语句
    a,b,c,d= 1,2,'c',{1}

          局部变量和代码块

    --局部变量和代码块  local
    
    x = 10
    local i = 1 
    while i <= x do
        local x = i * 2
        print(x)
        i = i + 1
    end

    循环和控制结构

    print("enter a number")
    n = io.read("*number")
    if n < 10 then
        print("我小于10")
    elseif n < 100 then  --elseif  不是else if 
        print("小于100")
    else
        print("其他")
    end    --最后要加end
    days = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}
    for key,value in pairs(days) do --构造pairs
        print(value)
    end
    
    revdays = {}
    for i, v in ipairs(days) do
        revdays[v] = i
    end
    
    for key, value in pairs(revdays) do
        print(key.."  "..value)
    end

    5、函数

    function maxium(a)
        local mi = 1 --maxium index
        local m = a[mi] --maxium value
        for i,val in ipairs(a) do
            if val > m then
                mi = i
                m = val
            end
        end
        return m, mi
    end
    
    
    print(maxium({3,64,9,10,32}))
  • 相关阅读:
    好的开源项目汇总
    强制SVN上传代码时添加日志
    微信开发-回调模式
    Struct2中自定义的Filter无效
    Ajax 传包含集合的JSON
    PostgreSQL数据库PL/PGSQL学习使用
    单用户对比PG 9.5.4和SYBASE 15.7对超大表的操作性能
    一场一波三折的SQL优化经历
    聚簇索引对数据插入的影响
    磁盘IO初探
  • 原文地址:https://www.cnblogs.com/jackStudy/p/4389608.html
Copyright © 2011-2022 走看看