zoukankan      html  css  js  c++  java
  • Lua初学习 9-13_02 元表与元方法

    1:元表与元方法

           测试001:

    student = {
    name = "cocotang",
    id = 10001,
    calss = "math",
    }
    function student:SayHello(name)
    print("student say hello to : "..name)
    end

    human = {
    name = "human",
    worldId = 10000001,
    }
    function human:SayHello(name)
    print("human say hello to : "..name)
    end

    setmetatable(student,human)
    human.__index=human
    student:SayHello("pikaboo")

    ======================debug===================

    student say hello to  : pikaboo

     

            测试002:

    student = {
    name = "cocotang",
    id = 10001,
    calss = "math",
    }
    function SayHello(name)
    print("student say hello to : "..name)
    end

    human = {
    name = "human",
    worldId = 10000001,
    }
    function human:SayHello(name)
    print("human say hello to : "..name)
    end

    setmetatable(student,human)
    human.__index=human
    student:SayHello("pikaboo")

    ======================debug=================

    human say hello to : pikaboo

     

    Q:student继承human( setmetatable(子table,父table) 父table.__index=父table)

     

     

     

  • 相关阅读:
    研究下
    linux 下wireshark安装与使用
    Spring优秀工具类Resource
    sunOS常用命令
    常用网站
    linux sar指令
    spring+quartz详解
    linux setenv 用法
    转hashmap非线程安全的解决办法
    gdb 调试core
  • 原文地址:https://www.cnblogs.com/cocotang/p/5867682.html
Copyright © 2011-2022 走看看