Giter Site home page Giter Site logo

luafrpf's Introduction

This script works on Lua and LuaJIT, it contains a ReadPropertiesFile (file, properties) function.

This function return a table, every index of table is a property. If you run with the next test config file:

How this works? Suppose you have the next properties file:

########################################################################
#                             Example                                  #
########################################################################

msg = "Hello world!"    # This string is correct
bad1 = Hello world!"    # This string isn't between two tokens
bad2 = Hello world!     # The " token is not present

trys = 1225             # This is a numeric configuration

pi = 3.1415             # Float
e = 2.71e-4             # Cientific notation
bad3 = 12c              # The error is mix numbers and not valid text

number = 1              # If you repeat some parameter
number = 2              # the value that get is the last
number = 3              # appear in the file. In this case 3.

########################################################################
#                               End                                    #
########################################################################

With ReadPropertiesFile (file, properties) you can get the values from the properties file if they exist in the table of properties that you pass as property. Let's an example:

dofile("LuaFRPF.lua")
function Print_Table (t) 
    for k, v in pairs (t) do print("\t"..tostring(k).."\t|\t"..tostring(v)) end
end
-- Load default value table
properties = {
        msg = "Hello",
        trys = 12,
        pi = 3.14,
        e = 0,-- The e parameter is not define
        number = 0,
        present = true
}
print("Properties default:")
Print_Table (properties)
-- Now load the configuration from file
properties = ReadPropertiesFile ("test.cnf", properties)
print("Properties from file:")
Print_Table (properties)

The output:

Properties default:
    number  |   0
    msg     |   Hello
    trys    |   12
    pi      |   3.14
    present |   true
    e       |   0
Properties from file:
    number  |   3
    msg     |   Hello world!
    trys    |   1225
    pi      |   3.1415
    present |   true
    e       |   0.000271

License in license.txt file.

Enjoy. Happy Hacking!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.