How to read a file with a moon?

1

What function do I use to read data from a file in Lua ?

For example:

lua_folder/
.... config.json
.... main.lua

I want to open this file config.json through Lua .

    
asked by anonymous 10.12.2015 / 13:31

1 answer

2

Make a function to do this like this:

 function file_getdata()
    local data_file_path = gre.SCRIPT_ROOT .. "/myfile.json"
    local f = io.open(data_file_path)
    f = io.read("*all")
    f = io.close()
    return f
 end

Source Code

    
10.12.2015 / 13:39