-- Å×À̺íÀ» ·ç¾Æ ÆÄÀÏ·Î ÀͽºÆ÷Æ® function fileOpen( file_name ) FileHandle = io.open( file_name, "w+" ) end function fileClose() io.close( FileHandle ) end -- Å×ÀÌºí ±íÀÌ tableDeep = -1 function printTab( offset ) local count = tableDeep+offset for i = 1, count do FileHandle:write( string.format( "\t" ) ) end end function table_to_luafile( table_name, t ) local t = t or _G[ table_name ] -- ·ç¾ÆÀÇ ¸ðµç ÇÔ¼ö¿Í Å×À̺íÀº _G Àü¿ª Å×À̺íÀÇ ¿ä¼Ò°¡ µÈ´Ù. tableDeep = tableDeep + 1 if tableDeep == 0 then FileHandle:write( string.format( "%s = {}\n\n", table_name ) ) end -- Å×À̺í À̸§ÀÌ ¹®ÀÚ¿­ÀÏ °æ¿ì¿£ ¹®ÀÚ¿­·Î, ¼ýÀÚÀÏ °æ¿ì¿£ ¾Æ¹«°Íµµ ÀûÁö ¾Ê´Â´Ù. if type(table_name) == "string" then printTab( 0 ) FileHandle:write( string.format("%s = \n", table_name) ) end printTab( 0 ) FileHandle:write( string.format("{ \n") ) for k, v in pairs(t) do if type(v) == "string" then v = string.format( "%q", v ) -- %q ´Â ·ç¾Æ ÀÎÅÍÇÁ¸®ÅͰ¡ ÀÐÀ» ¼ö ÀÖ´Â ¹®ÀÚ¿­·Î ÄÁ¹öÆÃÇØÁØ´Ù. end if type(v) == "boolean" then if v then v = "true" else v = "false" end end if type(v) == "table" then -- °ªÀÌ Å×À̺íÀÏ ¶§ table_to_luafile( k, v ) -- Ű °ªÀÌ ¹®ÀÚ°¡ µÉ ¼öµµ ÀÖ°í ¼ýÀÚ°¡ µÉ ¼öµµ ÀÖ°í. elseif type(k) == "number" then -- ۰¡ ¼ýÀÚÇüÀ϶§, printTab( 1 ) FileHandle:write( string.format( "%f,\n", v ) ) elseif type(v) == "number" then -- °ªÀÌ ¼ýÀÚÇüÀ϶§, printTab( 1 ) FileHandle:write( string.format( "%s = %f,\n", k, v ) ) else printTab( 1 ) FileHandle:write( string.format( "%s = %s,\n", k, v ) ) end end printTab( 0 ) FileHandle:write( "}" ) tableDeep = tableDeep - 1 if tableDeep ~= -1 then FileHandle:write( "," ) end FileHandle:write( "\n" ) end -- Á¤È®ÇÑ Å×ÀÌºí ¿ä¼ÒÀÇ °¹¼ö ¾ò±â function GetTableSize( table ) local size = 0 for _, _ in pairs(table) do size = size + 1 end return size end -- ÄÝ ½ºÅÃÀ» ¸®ÅÏÇÑ´Ù. function CallStack() local info = debug.getinfo( 3 ) return info.source..":"..info.currentline.." "..info.name.."()" end -- if type(v) == "table" then -- if type(k) == "number" then -- table_to_luafile( table_name .. "[" .. k .. "]", v ) -- else -- table_to_luafile( table_name .. "." .. k, v ) -- end -- else -- if type(k) == "number" then -- print( table_name .. "[" ..k.. "] = " .. v ) -- else -- print( table_name .. "." .. k .. " = " .. v ) -- end -- end -- end -- ´ÙÀ½°ú °°ÀÌ Ãâ·ÂÇØ º¸ÀÚ -- tt = { -- 100, -- { -- 1, -- 2, -- 3 -- }, -- inner = { -- 100, -- "¹®ÀÚ¿­", -- x = 10, -- alive = false -- }, -- x = 10 -- }