Skip to content

Instantly share code, notes, and snippets.

@oocytanb
Last active March 8, 2019 11:43
Show Gist options
  • Save oocytanb/1c017a50df8b14a64c73f54055c4e577 to your computer and use it in GitHub Desktop.
Save oocytanb/1c017a50df8b14a64c73f54055c4e577 to your computer and use it in GitHub Desktop.
Lua の変数情報を取得するスクリプト
----------------------------------------------------------------
-- Copyright (c) 2019 oO (https://github.com/oocytanb)
-- MIT Licensed
----------------------------------------------------------------
function ool_vars(v, indent, refTable)
if indent == nil then
indent = ''
end
if refTable == nil then
refTable = {}
end
local t = type(v)
if t == 'table' then
refTable[v] = refTable[v] and refTable[v] + 1 or 1
local str = '(' .. tostring(v) .. ') {\n'
local childIndent = indent .. ' '
for key, val in pairs(v) do
if type(val) == 'table' and refTable[val] and refTable[val] > 0 then
str = str .. childIndent .. key .. ': (' .. tostring(val) .. ')\n'
else
str = str .. childIndent .. key .. ': ' .. ool_vars(val, childIndent, refTable) .. '\n'
end
end
str = str .. indent .. '}'
refTable[v] = refTable[v] - 1
if (refTable[v] <= 0) then
refTable[v] = nil
end
return str
elseif t == 'function' or t == "thread" or t == "userdata" then
return '(' .. t .. ')'
elseif t == 'string' then
return '(' .. t .. ') ' .. string.format('%q', v)
else
return '(' .. t .. ') ' .. tostring(v)
end
end
--[[
print('\n_G: ' .. ool_vars(_G))
-- Output @VCAS 1.5.1c
_G: (table: 00000004) {
_G: (table: 00000004)
_VERSION: (string) "MoonSharp 2.0.0.0"
_MOONSHARP: (table: 00000005) {
version: (string) "2.0.0.0"
luacompat: (string) "5.2"
platform: (string) "limited.unity.dll.mono.clr4.aot"
is_aot: (boolean) true
is_unity: (boolean) true
is_mono: (boolean) true
is_clr4: (boolean) true
is_pcl: (boolean) false
banner: (string) "MoonSharp 2.0.0.0 [limited.unity.dll.mono.clr4.aot]\r\
Copyright (C) 2014-2016 Marco Mastropaolo\r\
http://www.moonsharp.org\r\
"
}
ipairs: (function)
pairs: (function)
next: (function)
type: (function)
assert: (function)
collectgarbage: (function)
error: (function)
tostring: (function)
select: (function)
tonumber: (function)
print: (function)
setmetatable: (function)
getmetatable: (function)
rawget: (function)
rawset: (function)
rawequal: (function)
rawlen: (function)
string: (table: 00000017) {
dump: (function)
char: (function)
byte: (function)
unicode: (function)
len: (function)
match: (function)
gmatch: (function)
gsub: (function)
find: (function)
lower: (function)
upper: (function)
rep: (function)
format: (function)
reverse: (function)
sub: (function)
startsWith: (function)
endsWith: (function)
contains: (function)
}
package: (table: 00000018) {
loaded: (table: 00000019) {
string: (table: 00000017) {
dump: (function)
char: (function)
byte: (function)
unicode: (function)
len: (function)
match: (function)
gmatch: (function)
gsub: (function)
find: (function)
lower: (function)
upper: (function)
rep: (function)
format: (function)
reverse: (function)
sub: (function)
startsWith: (function)
endsWith: (function)
contains: (function)
}
table: (table: 0000002D) {
unpack: (function)
pack: (function)
sort: (function)
insert: (function)
remove: (function)
concat: (function)
}
math: (table: 00000038) {
abs: (function)
acos: (function)
asin: (function)
atan: (function)
atan2: (function)
ceil: (function)
cos: (function)
cosh: (function)
deg: (function)
exp: (function)
floor: (function)
fmod: (function)
frexp: (function)
ldexp: (function)
log: (function)
max: (function)
min: (function)
modf: (function)
pow: (function)
rad: (function)
random: (function)
randomseed: (function)
sin: (function)
sinh: (function)
sqrt: (function)
tan: (function)
tanh: (function)
pi: (number) 3.14159265358979
huge: (number) 1.79769313486232E+308
}
coroutine: (table: 00000055) {
create: (function)
wrap: (function)
resume: (function)
yield: (function)
running: (function)
status: (function)
}
bit32: (table: 0000005C) {
extract: (function)
replace: (function)
arshift: (function)
rshift: (function)
lshift: (function)
band: (function)
btest: (function)
bor: (function)
bnot: (function)
bxor: (function)
lrotate: (function)
rrotate: (function)
}
dynamic: (table: 00000069) {
eval: (function)
prepare: (function)
}
os: (table: 0000006C) {
clock: (function)
difftime: (function)
time: (function)
date: (function)
}
json: (table: 00000071) {
parse: (function)
serialize: (function)
isnull: (function)
null: (function)
}
}
}
table: (table: 0000002D) {
unpack: (function)
pack: (function)
sort: (function)
insert: (function)
remove: (function)
concat: (function)
}
unpack: (function)
pack: (function)
pcall: (function)
xpcall: (function)
math: (table: 00000038) {
abs: (function)
acos: (function)
asin: (function)
atan: (function)
atan2: (function)
ceil: (function)
cos: (function)
cosh: (function)
deg: (function)
exp: (function)
floor: (function)
fmod: (function)
frexp: (function)
ldexp: (function)
log: (function)
max: (function)
min: (function)
modf: (function)
pow: (function)
rad: (function)
random: (function)
randomseed: (function)
sin: (function)
sinh: (function)
sqrt: (function)
tan: (function)
tanh: (function)
pi: (number) 3.14159265358979
huge: (number) 1.79769313486232E+308
}
coroutine: (table: 00000055) {
create: (function)
wrap: (function)
resume: (function)
yield: (function)
running: (function)
status: (function)
}
bit32: (table: 0000005C) {
extract: (function)
replace: (function)
arshift: (function)
rshift: (function)
lshift: (function)
band: (function)
btest: (function)
bor: (function)
bnot: (function)
bxor: (function)
lrotate: (function)
rrotate: (function)
}
dynamic: (table: 00000069) {
eval: (function)
prepare: (function)
}
os: (table: 0000006C) {
clock: (function)
difftime: (function)
time: (function)
date: (function)
}
json: (table: 00000071) {
parse: (function)
serialize: (function)
isnull: (function)
null: (function)
}
ExportVci: (userdata)
ExportStudio: (userdata)
ExportShared: (userdata)
ExportMe: (userdata)
ExportAssets: (userdata)
ExportTransform: (userdata)
ExportState: (userdata)
Vector2: (userdata)
Vector3: (userdata)
Vector4: (userdata)
Color: (userdata)
Quaternion: (userdata)
Matrix4x4: (userdata)
TimeSpan: (userdata)
}
]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment