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)

     

     

     

  • 相关阅读:
    #define中的特殊符号
    c++ windows下计时
    c++内存池
    u3d 场景资源打包
    Unity3d 动态加载材质方法
    Unity3D Shader基础教程
    Unity3D Shader入门指南(一)
    Unreal发展史
    阴影锥(shadow volume)原理与展望
    软硬RAID 和 不常见的RAID
  • 原文地址:https://www.cnblogs.com/cocotang/p/5867682.html
Copyright © 2011-2022 走看看