Git Product home page Git Product logo

lua2go's Introduction

Accessing Go via Lua

This module enables easy access to Go modules from LuaJit and therefore, NGINX with the LuaJit module. So if you need the capabilities of Go in your NGINX processing, you've come to the right place!

Note: Lua2Go is now available from LuaRocks: http://luarocks.org/modules/scottganyo/lua2go

To use (see also the example:

  1. Write your Go module and export your functions:

    //export add
    func add(operand1 int, operand2 int) int {
        return operand1 + operand2
    }
    
  2. Build your go module as a shared library:

    go build -buildmode=c-shared -o example.so example.go

  3. Include a bit of setup in your Lua file:

    local lua2go = require('lua2go')
    local example = lua2go.Load('./example.so')
    
  4. Register your extern declarations from your header file (example.h) in your Lua:

    lua2go.Externs[[
      extern GoInt add(GoInt p0, GoInt p1);
    ]]
    
  5. Call your Go function from Lua (see example for more detail):

    local result = lua2go.ToGo(example.add(1, 1))
    
  6. Run your app:

    luajit myapp.lua

  7. Bask in the glory of all that you've accomplished!

  8. To see how Lua2Go can be incorporated into NGINX, check out the benchmark example.

Enjoy!

lua2go's People

Contributors

theganyo avatar

Watchers

 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.