Giter VIP home page Giter VIP logo

xlb's Introduction

xLB ( ver 0.0.1 )

xlb is another library for binding C++ to Lua. It depends on C++17, and it's just one header file.

Features

  • function
  • callback function
  • class ( member data and function )
  • inherited function
  • overload function ( do not recommend )
  • constant and namespace
  • default value for function
  • dereference from pointer
  • get address of value

Do not support yet

  • operator overload

Usage

  • module and const integral
    xlb_module(L, MODULE_NAME) ({
            xlb_const("WINVER", WINVER)
    });
  • function
    xlb_module(L, MODULE_NAME) ({
            xlb_f("malloc", malloc),
            xlb_f("free", free)
    });
  • callback as class
    xlb_module(L, MODULE_NAME) ({
        xlb_class<xlb_cbf<WNDENUMPROC>>("EnumWindowsProc").constructor<xlb_luafunc>(),
    });
    function EnumWindows()
        luawin.load_wmsg();
        local len = 1024;
        local buff = string.rep('\0', len);
        local EnumWindowsProc = luawin.EnumWindowsProc(function(hwnd, lParam) 
            local len = luawin.GetWindowText(hwnd, buff, len);
            print('---' .. string.sub(buff, 1, len) .. ',' .. lParam);
            return true; 
        end);
        luawin.EnumWindows(EnumWindowsProc, 999);
    end

maybe Output is :

    ---MSCTFIME UI,999
    ---Default IME,999
  • inherited
    xlb_module(L, MODULE_NAME) ({
        xlb_class<classB>("classB")
            .inherited<classA>()
            .constructor<>()
            .destructor()
    });
  • tag struct and property
    xlb_module(L, MODULE_NAME) ({
        xlb_class<PRINTPAGERANGE>("PRINTPAGERANGE") .constructor<>() .destructor()
            .property("nFromPage", &PRINTPAGERANGE::nFromPage)
            .property("nToPage", &PRINTPAGERANGE::nToPage)
    });
  • create object with new in place ( malloc and free )
    require 'luawin'
    luawin.load_base();
    function BASE()
        luawin.load_dialog();
        print('---sizeof PRINTPAGERANGE=' .. luawin.PRINTPAGERANGE.typesize); 
        local a = luawin.malloc(luawin.PRINTPAGERANGE.typesize);
        print('---a=' .. luawin.type(a));
        local b = luawin.PRINTPAGERANGE:newin(a);
        b.nFromPage = 1;
        b.nToPage = 2;
        print('---b.nFromPage=' .. b.nFromPage);
        print('---b.nToPage=' .. b.nToPage);
        print('---b=' .. luawin.type(b));
        b = nil;
        collectgarbage();
        print('--');
        luawin.free(a);
    end

maybe Output is:

    ---sizeof PRINTPAGERANGE=8
    ---a=(0x000001B028EA7720 : T*)
    ---b.nFromPage=1
    ---b.nToPage=2
    ---b=(0x000001B028EA7720 : T)

Sample

  • bind Windows API to Lua ( BASE, MESSAGE, GUI, Dialog and SNMP )

License

xlb's People

Contributors

wunoman avatar

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.