Giter Club home page Giter Club logo

luaconf's Introduction

luaconf the configuration library
(C) 2009 Peter Kasza

What is luaconf?
    It is a lightweight "library" for retrieving variables from lua configuration scripts.
    Well, its not really a library, more like an example on how to do the aforementioned.

Usage:
    -- Write default configuration values to luaconf.i
        and generate the luaconf_wrap.cxx using swig

    -- in your program write something like this:
        lua_State* L = luaL_newstate();
        luaL_openlibs(L);
        luaopen_luaconf(L);

        if (luaL_dofile(L, config_file) != 0) {
            printf("couldn't parse file: %s\n", config_file);
        }

        // use lua_evalexpr here
        lua_close(L);

    -- use lua_evalexpr to retrieve configuration values (with printf style fmt strings)
        int my_value = lua_evalexpr(L, lua_tointeger, "luaconf.config.my_value");

    -- compile and link your program with luaconf_wrap.cxx and liblua.

    -- Enjoy!

Q & A:
    Q: Help! I can't use lua_tostring!
    A: Of course you can't. It's a macro not a function.
       Use the lua_tocstring function instead (defined in luaconf.hpp).

    Q: How do I retrieve the length of an array?
    A: Using normal lua expressions (note the '#' in front of the variable):

        int length = lua_evalexpr(L, lua_tointeger, "#luaconf.config.array_variable");

    Q: Do I have to mess with string manipulation to retrieve programmatic variables?
    A: No, you can use lua_evalexpr, it actually works like printf :)
       For example, you can write something like this to retrieve array elements:

        for (int i = 0; i < length; i++)
            a[i] = lua_evalexpr(L, lua_tointeger,
                "#luaconf.config.array_variable[%d]", i);

    Q: What callback functions can I use?
    A: You can use the following:
        lua_tointeger for converting to integers,
        lua_tonumber for floating point numbers and
        lua_tocstring for character arrays.

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.