How to read a file with moon?

Asked

Viewed 872 times

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 the Lua.

1 answer

2

Do a function to do it 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 of the code

Browser other questions tagged

You are not signed in. Login or sign up in order to post.