Showing posts with label lua. Show all posts
Showing posts with label lua. Show all posts

Thursday, 3 July 2014

How to install Luarocks from sources in Debian


In this article we are going to install luarocks software in a Debian box.


Luarocks is a system to manage and deploy lua modules ("rocks").

It also tracks and installs needed dependencies when installing a new lua rock.

luarocks.org official web site.


Install lua


First we need lua scripting language to be installed. (I get lua 5.2 version)

$ sudo aptitude install lua5.2


Lua development files will also be necessary to compile sources afterwards.

$ sudo aptitude install liblua5.2-dev


Get and compile luarocks source code


Get luarocks source code

Sunday, 16 June 2013

How to call BTC-e API using LUA language


BTC-e.com is a web site where you can exchange virtual coins (like bitcoins, litecoins, etc), US dollars, euros and Russian rubles.

It provides a web interface for you to manually interact with.

Also if you are interested in building a bot to perform operations automatically, you could use their API.


In this article I am going to call the API from my Debian Sid system using Lua language.


Install Lua and dependencies


First I install lua 5.1 and luarocks to manage lua rocks.
$ sudo aptitude install lua5.1
$ sudo aptitude install luarocks

Once luarocks is already installed I install luasockets, and luasec. This will allow us to perform request using https protocol.
$ sudo luarocks install luasocket
$ sudo luarocks install luasec


INSTALL SHA2

http://code.google.com/p/sha2

Next we install sha2 rock to calculate hmac sha512 hashes.
$ sudo luarocks install sha2
$ cd /usr/local/lib/luarocks/rocks/sha2
$ sudo aptitude install lua-filesystem
$ sudo aptitude install lua5.1-md5-dev

Now we perform the tests:
$ lua test_sha2.lua
$ lua test_hmac.lua
They should pass OK.


INSTALL JSON

Monday, 17 September 2012

LUA PRIME CALCULATOR using preprocessing based on Sieve of Eratosthenes


This article shows a lua script to calculate an ordered prime list starting with 2, 3, 5, 7, etc.


We are going to improve former lua prime calculator using a preprocessing table.
This table will allow us to discard quickly some numbers and its multiples.

Within this lua script, first we perform some preprocessing, and after that actual prime testing for remaining numbers are performed.


Sieve of Eratosthenes


Sieve of Eratosthenes is an algorithm to calculate a prime number list up to a chosen number.

In this program we will use this algorithm to generate a preprocessing table.


Some examples are useful to show how preprocessing table works:

Tables are generated using a sequence with first prime numbers.

E.g:

Preprocessing table for 2

{2}

So we will test numbers this way:
We start with number one, and sum to it the first number from preprocessing table:
1+2 = 3 (3 is the next number to test for primality)

Once preprocessing table has completed, we start from first element again (2):
3+2 = 5

5+2 = 7

Sunday, 29 July 2012

Lua: Calculate a prime number list

Lua is an extension language.


This script calculates a prime number list starting with smaller ones.


To run this script you need to install lua language: (e.g: in Debian or Ubuntu)
$ sudo aptitude install lua

Current version(when this article was written) is 5.1:
$ sudo aptitude install lua5.1


After installing it, lua interpreter could be found in /usr/bin/lua.

Then you copy this script in a file, e.g: primes.lua and exec:

$ lua primes.lua 20 # it will calculate first twenty prime numbers.

or give execution permissions to the file:
$ chmod a+x primes.lua
$ ./primes.lua 20