Giter Club home page Giter Club logo

sys's Introduction

Lua system package

Note: some functions only work on UNIX systems.

Dependencies

Torch7 (www.torch.ch)

Install

$ luarocks install sys

Use

$ torch
> require 'sys'

Time / Clock

> t = sys.clock()  -- high precision clock (us precision)
> sys.tic()
> -- do something
> t = sys.toc()    -- high precision tic/toc
> sys.sleep(1.5)   -- sleep 1.5 seconds

Paths

> path,fname = sys.fpath()

Always returns the path of the file in which this call is made. Useful to access local resources (non-lua files).

Execute

By default, Lua's os.execute doesn't pipe its results (stdout). This function uses popen to pipe its results into a Lua string:

> res = sys.execute('ls -l')
> print(res)

Derived from this, a few commands:

> print(sys.uname())
linux

UNIX-only: shortcuts to run bash commands:

> ls()
> ll()
> lla()

sys.COLORS

If you'd like print in colours, follow the following snippets of code. Let start by listing the available colours

$ torch
> for k in pairs(sys.COLORS) do print(k) end

Then, we can generate a shortcut c = sys.COLORS and use it within a print

> c = sys.COLORS
> print(c.magenta .. 'This ' .. c.red .. 'is ' .. c.yellow .. 'a ' .. c.green .. 'rainbow' .. c.cyan .. '!')

sys's People

Contributors

atcold avatar borisfom avatar btnc avatar clementfarabet avatar colesbury avatar koraykv avatar linusu avatar nagadomi avatar samehkhamis avatar soumith avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sys's Issues

recent version breaks lzmq.threads

a recent commit (@7588fbd1) breaks lzmq.threads (https://github.com/zeromq/lzmq).

in the context of lzmq.threads, arg might contain the following content:

{ "first argument", "second argument", "third argument",
  [0] = "=(loadstring)",
  n = 3
}

the variables i and v within find_prefix will thus contain the following values:

0   "=(loadstring)"
1   "first argument"
2   "second argument"
3   "third argument"
"n" 3

the comparison i <= 0 will eventually fail with the following message:

sys/init.lua:99: attempt to compare number with string

Add 1.1 rockspec

The latest set of changes removes a number of functions, so some existing code may break. How about tagging 5f8c734 as 1.0 and adding a v1.1 rockspec pointing to HEAD? That way we can keep existing code working by just modifying our rockspecs.

It is impossible to build the library if "share/cmake/torch" is not in PATH

I am building the library via a script which subsequently calls "luarocks make XXX" where XXX are cwrap, paths, torch, sys, ...

"FIND_PACKAGE(Torch REQUIRED)" fails because -DCMAKE_PREFIX_PATH="$(LUA_BINDIR)/.." was removed in sys-1.1-0.rockspec

There is no such problem for other torch modules like optim, graph, ... because they contain DCMAKE_PREFIX_PATH="$(LUA_BINDIR)/.."

see discussion #7

Possible bug or unimplemented functionality in sys.fexecute()

The parameter "readwhat" is not used, but is referenced from the parallel module (see the code for forking).

Proposed fix:

function sys.fexecute(cmd, readwhat)
*+ readwhat = readwhat or 'all'
local tmpfile = os.tmpname()
local cmd = cmd .. ' 1>'.. tmpfile..' 2>' .. tmpfile
os.execute(cmd)
local file = G.assert(io.open(tmpfile))
*- local s = file:read('all')
+ local s= file:read(readwhat)
file:close()
s = s:gsub('^%s
',''):gsub('%s_$','')
os.execute('rm ' .. tmpfile)
return s
end

`sys.execute()` causes exception in OpenResty

For some reason: https://github.com/torch/sys/blob/master/init.lua#L37-L40 is returning nil when launched through OpenResty which causes an exception.

app.lua

local sys = require 'sys'

Running resty app.lua results in:

$ resty app.lua 
/Users/vanpelt/torch/install/share/lua/5.1/sys/init.lua:40: attempt to index local 's' (a nil value)

(sys.execute is being called to set sys.prefix)

I have no clue why popen is behaving strangely, but thought the nil output case should be handled. Any idea's why child processes are failing in this context?

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.