Coder Social home page Coder Social logo

gopher-lua-libs's Introduction

gopher-lua-libs

GoDoc

Package contains is a libs for gopher-lua.

License

Development version, available on github, released under BSD 3-clause.

Installation

go get github.com/vadv/gopher-lua-libs

Index

Usage

For the quick overview you can use standalone interpreter with listed libs. Examples and documentation for modules can be found in their directories.

go install github.com/vadv/gopher-lua-libs/cmd/glua-libs@latest

glua-libs example.lua

This example shows basic usage of this libs in your code

package main


import (
        "log"
        "flag"
        "os"

        lua "github.com/yuin/gopher-lua"
        libs "github.com/vadv/gopher-lua-libs"

)
var (
        exec = flag.String("execute", "", "execute lua script")
)


func main() {
        flag.Parse()
        state := lua.NewState()
        defer state.Close()
        libs.Preload(state)
        if *exec != `` {
                if err := state.DoFile(*exec); err != nil {
                        log.Printf("[ERROR] Error executing file: ", err)
                }
        } else {
                log.Println("Target file was not given!")
                os.Exit(0)
        }
}

gopher-lua-libs's People

Contributors

alexjx avatar cloudwindy avatar dependabot[bot] avatar iyear avatar scr-oath avatar spigell avatar vadv avatar vasilev avatar wangsongyan avatar waschik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gopher-lua-libs's Issues

YAML encoding

The json library supports both Encoding and Decoding.
Would you accept a PR to make YAML encoding work, too?
This would simplify the work I've done in my own library.
As I'd like to have your extensions to use.

Broken ci runs with fresh packages

Greetings. Just warning. With recent updates of cbroglie/mustache and go-sql-driver/mysql CI runs is broken. Go modules not working there, because Travis worker clones git repo and put it inside GOPATH and GO111MODULE set to 'auto'.

go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src;

	ignoring go.mod;

	see 'go help modules'

This behavior changed in go 1.13 - https://github.com/golang/go/wiki/Modules#recent-changes

Refered issues:
cbroglie/mustache#36
go-sql-driver/mysql#1040

With next update of this dependencies glua-libs can't be compiled with go < 1.13

Unknown type error in db plugin (pg)

Greetings!
Thank you for your libs.
If I make select query against type timestamp

query:
local result, err = pg:query("SELECT insert_date FROM table WHERE state = 0 LIMIT 1")

parse:
for _, r in pairs(result.rows) do
    for id, column in pairs(result.columns) do
        print(column, r[id])
    end
end
2019/01/15 18:25:11 [ERROR] unknown type (value: `time.Time{wall:0xfd2b478, ext:63683068860, loc:(*time.Location)(0xc0001d41e0)}`, converted: `time.Time{wall:0xfd2b478, ext:63683068860, loc:(*time.Location)(0xc0001d41e0)}`)


insert_date	nil

Is it possible to convent it to right type?
In typelist of Gopher-lua I did not found type time.
Thanks!

Usage http.server as plugin after error

Greetings! I try to start http service as plugin. But if main loop tries to restart server after error I got error binding for port. This is example.

local plugin = require("plugin")
local time = require("time")


local plugin_server = [[
http = require("http")
inspect = require("inspect")

s = {}

local server, err = http.server("127.0.0.1:5001")
if err then error(err) end

function s.start()
  while true do
    local req, resp = server:accept()
    print(inspect(req))

    if req then 
    
      print("received")
      resp:code(500)
      resp:done()

      error("I am broken")
    end
  end
end


s.start()
]]



server = plugin.do_string(plugin_server)
server:run()

while true do
  time.sleep(1)
  if not server:is_running() then
    print("error:", tostring(server:error()))
    server:run()
  end
end
error:	<string>:20: I am broken
stack traceback:
	[G]: in function 'error'
	<string>:20: in function 'start'
	<string>:26: in main chunk
	[G]: ?
error:	<string>:7: listen tcp 127.0.0.1:5001: bind: address already in use
stack traceback:
	[G]: in function 'error'
	<string>:7: in main chunk
	[G]: ?

Is any way to use http.server like this?
Thank you!

Function to push 3rd party modules to plugin package

Greetings. Let's assume we have any golang package for glua-libs in somewhere outside of this repo. For example, ssh - https://github.com/spigell/luscheduler/tree/master/libs/ssh. There is no big deal to add glua-libs and custom resources to project, but if we will use plugin package with 3rd party modules inside then it seems to not loading.

local plugin = require("plugin")

local plugin_body = [[
    local time = require("time")
    local chef = require("chef")
    local cron = require("ssh")

    local i = 1
    print(i)
    time.sleep(2)
]]

local string_plugin = plugin.do_string(plugin_body)
string_plugin:run()

time.sleep(1)
if file_plugin:is_running() then
  print("RUNNING")
else
  print("NOT RUNNING")
  print(string_plugin:error())
end

NOT RUNNING
<string>:3: module ssh not found:
	no field package.preload['ssh']
	stat ./ssh.lua: no such file or directory
	stat /usr/local/share/lua/5.1/ssh.lua: no such file or directory
	stat /usr/local/share/lua/5.1/ssh/init.lua: no such file or directory, 
stack traceback:
	[G]: in function 'require'
	<string>:3: in main chunk
	[G]: ?

In plugin package creates a new Lua state with only static list of modules - https://github.com/vadv/gopher-lua-libs/blob/master/plugin/api.go#L75
Is there any change add modules to preload table in the state?

Loader returned by require contains only Lua table with methods without metadata and do not fit for PreloadModules function.

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.