Here's another of these list of links post: About JIT and Luajit.
This is hardcore stuff. I've read all the articles but honestly, I barely get what I'd have to do to write something with this on my own.
Anyway...
The luapower site is full of nice tricks for lua libraries. Highly recommended (at least skim it). Specially the design of glue and lua&luajit tricks.
edit: Also, a brainfuck compiler using dynasm
Cya!
martes, 1 de julio de 2014
miércoles, 21 de mayo de 2014
multiple value return in lua
Lua functions can return multiple values, and the language will natively assign them to the variables on the other side of the equal sign.
local a, b = (function() return 1,2 end)() print(a,b) => 1 2That's fine, but when things get a bit more tricky is when the values are not returned in tail call position.
local a, b = (function() local res = (function() return 1 , 2 end)() return res end)() print(a, b) => 1 nilThe catch is that lua assigns the 'rest' of the values only to the last element of tables, or argument lists. If we want to wrap a function into another while not being in tail position, we have to use a little trick. This trick is unpack.
local a, b = (function() local res = {(function() return 1 , 2 end)()} return unpack(res) end)() print(a, b) => 1 2
jueves, 8 de mayo de 2014
Presenting Eva
I've hacked a tiny little lisp interpreter in lua, and I called Eva, for obvious reasons.
It's not pretty, it's not complete at all. Hell, it doesn't even have strings, you can't call native lua functions, and there are no conses (although you could get them using functions for that).
The whole point of it was to have some fun implementing a tiny lisp-like thingie, and to make it in lua, which is a language that I like quite a lot (although some of its table missfeatures make me cry sometimes)
Without further ado, Eva .
It's not pretty, it's not complete at all. Hell, it doesn't even have strings, you can't call native lua functions, and there are no conses (although you could get them using functions for that).
The whole point of it was to have some fun implementing a tiny lisp-like thingie, and to make it in lua, which is a language that I like quite a lot (although some of its table missfeatures make me cry sometimes)
Without further ado, Eva .
miércoles, 7 de mayo de 2014
erc makes you faster at jokes!
Hi, today's post is a simple sinppet I wrote to ease the pain of looking for recurrent references on the internet.
At work we use IRC heavily (it's our main channel for comunication). As you know,every platform or channel of comunication has its own processes and joke (slightly related (but interesting nonetheless): The medium is the Massage ) . So IRC is mostly about sending links to gifs and to funny images, and funny images with captions in them.
It's so simple that it doesn't even need explanation. You just have to know that all defuns named "erc-cmd-SOMETHING" will be automatically callable from erc as a /something.
Combined with erc-image.el, it makes a really nice IRC experience :)
At work we use IRC heavily (it's our main channel for comunication). As you know,every platform or channel of comunication has its own processes and joke (slightly related (but interesting nonetheless): The medium is the Massage ) . So IRC is mostly about sending links to gifs and to funny images, and funny images with captions in them.
It's so simple that it doesn't even need explanation. You just have to know that all defuns named "erc-cmd-SOMETHING" will be automatically callable from erc as a /something.
(defun erc-cmd-MEME (wat) "Fetch links from the alist of knowledge" (let ((h '(("trap" "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM1KvHzrpRDpci5HCGe7mjpaRQ3uKRgNjbyTpUG6B8nG_qXnxGT2ccuskYnK_FlvsOLxX8jYIJIHsWYYAlMCqP77UaQRSrBkoILLHy3noG7cHhGcYpUrLA3iMGkczBE8FS-7G5sDuu9X_1/s1600/original.jpg")))) (erc-send-message (cadr (assoc wat h)))))
Combined with erc-image.el, it makes a really nice IRC experience :)
viernes, 28 de marzo de 2014
git reset. again
This is shamelessly copied from the web archive.
Assume you start from a "everything is committed and golden" state. Let's pretend you came to this starting point via a
Assume you start from a "everything is committed and golden" state. Let's pretend you came to this starting point via a
git checkout
: and then you
edit a bunch of stuff, compile/test, and then git add
and git
commit
:$ git checkout mywork
...edit edit edit...
$ git add ...
$ git commit
If at this point you do a git reset
, here's how the type of reset
("soft", "hard", or the default, which is "mixed") affects things:$ git checkout mywork
# --hard resets to this point
...edit edit edit...
# --mixed (default) resets to this point
$ git add ...
# --soft resets to this point
$ git commit
Also note, as gitster says, that git commit --amend
makes the git
reset --soft
mostly redundant.
jueves, 27 de marzo de 2014
sed vs unix
UNIX | SED -------------+---------------------------------------------------------------- cat | sed ':' cat -s | sed '1s/^$//p;/./,/^$/!d' tac | sed '1!G;h;$!d' grep | sed '/patt/!d' grep -v | sed '/patt/d' head | sed '10q' head -1 | sed 'q' tail | sed -e ':a' -e '$q;N;11,$D;ba' tail -1 | sed '$!d' tail -f | sed -u '/./!d' cut -c 10 | sed 's/\(.\)\{10\}.*/\1/' cut -d: -f4 | sed 's/\(\([^:]*\):\)\{4\}.*/\2/' tr A-Z a-z | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' tr a-z A-Z | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' tr -s ' ' | sed 's/ \+/ /g' tr -d '\012' | sed 'H;$!d;g;s/\n//g' wc -l | sed -n '$=' uniq | sed 'N;/^\(.*\)\n\1$/!P;D' rev | sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//' basename | sed 's,.*/,,' dirname | sed 's,[^/]*$,,' xargs | sed -e ':a' -e '$!N;s/\n/ /;ta' paste -sd: | sed -e ':a' -e '$!N;s/\n/:/;ta' cat -n | sed '=' | sed '$!N;s/\n/ /' grep -n | sed -n '/patt/{=;p;}' | sed '$!N;s/\n/:/' cp orig new | sed 'w new' orig hostname -s | hostname | sed 's/\..*//'shamelessly copypasted from here
sábado, 22 de marzo de 2014
More Lua iterators
After the permutations post, I thought that we needed something like a 'take' function, that would allow us to use infinite streams safely.
local function take(n, it , param, state) local count = 0 return function() count = count+1 if count <= n then return it() end return nil end end local function take_while(fun, it , param, state) return function() if fun() then return it() end return nil end end
Simple but nice.
Suscribirse a:
Entradas (Atom)