Skip to content

Commit cda514f

Browse files
committed
Lua面向对象3
1 parent 2919423 commit cda514f

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

Lua-Script/oop/oop4.lua

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
--
2+
-- Created by IntelliJ IDEA.
3+
-- User: Administrator
4+
-- Date: 2017/5/25
5+
-- Time: 17:02
6+
-- To change this template use File | Settings | File Templates.
7+
----------------------------------------------------------- Lua面向对象2
8+
-- local smartMan = {
9+
-- name = "Tinywan",
10+
-- age = 26,
11+
-- money = 800000,
12+
-- sayHello = function()
13+
-- print("Tinywan say 大家好")
14+
-- end
15+
-- }
16+
-- local t1 = {}
17+
-- local mt = {
18+
-- __index = smartMan,
19+
-- __newindex = function(table, key, value)
20+
-- print(key .. "字段不存在不要试图给他赋值")
21+
-- end
22+
-- }
23+
-- setmetatable(t1, mt)
24+
-- t1.sayHello = function()
25+
-- print("HAHA")
26+
-- end
27+
-- t1.sayHello()
28+
----- 输出结果
29+
---- sayHello字段不存在不要试图给他赋值
30+
---- Tinywan say 大家好
31+
32+
----------------------------------------------------------- Lua面向对象3
33+
-- local smartMan = {
34+
-- name = "none"
35+
-- }
36+
-- local other = {
37+
-- name = "大家好,我是无赖的table"
38+
-- }
39+
-- local t1 = {}
40+
-- local mt = {
41+
-- __index = smartMan,
42+
-- __newindex = other
43+
-- }
44+
-- setmetatable(t1, mt)
45+
-- print("other的名字,赋值前:" .. other.name)
46+
-- t1.name = "峨眉大侠"
47+
-- print("other的名字,赋值后:" .. other.name)
48+
-- print("t1 的名字:" .. t1.name)
49+
----- 输出结果
50+
---- other的名字,赋值前:大家好,我是无赖的table
51+
---- other的名字,赋值后:峨眉大侠
52+
---- t1 的名字:none
53+
54+
----------------------------------------------------------- Lua面向对象3
55+
a = 'fdfd'
56+
for n in pairs(_G) do
57+
print(n) -- 打印全局的函数和变量
58+
end
59+
60+
--输出结果
61+
--coroutine
62+
--assert
63+
--tostring
64+
--tonumber
65+
--io
66+
--rawget
67+
--xpcall
68+
--arg
69+
--ipairs
70+
--print
71+
--pcall
72+
--gcinfo
73+
--module
74+
--setfenv
75+
--getfenv
76+
--pairs
77+
--jit
78+
--bit
79+
--package
80+
--error
81+
--debug
82+
--loadfile
83+
--rawequal
84+
--loadstring
85+
--rawset
86+
--unpack
87+
--table
88+
--require
89+
--_VERSION
90+
--newproxy
91+
--collectgarbage
92+
--dofile
93+
--next
94+
--math
95+
--load
96+
--os
97+
--_G
98+
--select
99+
--string
100+
--type
101+
--getmetatable
102+
--a (自己定义的也出来了)
103+
--setmetatable
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+

0 commit comments

Comments
 (0)