zoukankan      html  css  js  c++  java
  • lua中的table

    mytable = { hello}
    print(table.getn(mytable))
    --结果为0 不加引号不计入元素的 不加引号表示索引值, 如果赋值可以用mytable["hello"]或mytable.hello来访问

    mytable = { "hello" }
    print(table.getn(mytable))
    --结果为1, 表示mytable[1元素的值为"hello"字符串


    mytable =
    {
        hello = "hello",world = "world",
        {
            x = 100, y = 100
        };
        {
            x = 200, y = 200
        }
    }

    print(table.getn(mytable))

    for i = 1, table.getn(mytable)
    do
        str = string.format("index %d: x = %d, y = %d", i, mytable[i].x, mytable[i].y)
        print(str)
    end

    print(mytable["hello"])
    print(mytable.world)

    mytable = { hello, world}
    print(table.getn(mytable))
    print(mytable.hello, mytable[1])
    --0
    --
    nil nil


    mytable = { "hello"}
    print(table.getn(mytable))
    print(mytable.hello, mytable[1])
    --1
    --
    nil nil
    --
    ----------------结果如下-------------------

    >lua -e "io.stdout:setvbuf 'no'" "test.lua" 
    2
    index 1: x = 100, y = 100
    index 2: x = 200, y = 200
    hello
    world
    0
    nil    nil
    1
    nil    hello
    >Exit code: 0

    --lua表中可以用,也可以用分号, 没区别 

  • 相关阅读:
    GIL 全局解释器
    线程
    队列 Queue 与 生产者消费模型
    进程 与 并发(进程打开方式,互斥锁)
    【JAVA设计模式】单例模式
    【排序】桶排序
    【排序】选择排序
    【排序】插入排序
    【排序】冒泡排序
    JVM 优化之逃逸分析
  • 原文地址:https://www.cnblogs.com/barrysgy/p/2345023.html
Copyright © 2011-2022 走看看