Skip to content

Instantly share code, notes, and snippets.

View pablomayobre's full-sized avatar
📖
Learning new technologies

Pablo Ariel Mayobre pablomayobre

📖
Learning new technologies
  • NewCombin
  • Trelew, Chubut, Argentina
View GitHub Profile
@pablomayobre
pablomayobre / bite.lua
Created April 2, 2016 20:13
Bite is a common bit operations interface that uses BitOps, bit32, Lua 5.3 bit operators or plain Lua bit operations (The api is the same as BitOps plus some functions from bit32)
local bit = {}
local normalize = function (...)
local t = {}
for k,v in ipairs{...} do
t[k] = v <= 0x7fffffff and v or -(bit.bnot(v) + 1)
end
end
--LuaJIT BitOp library
@pablomayobre
pablomayobre / shake
Created April 2, 2016 01:30
Screen shake for Lua
--Based on S0lll0s code https://love2d.org/forums/viewtopic.php?f=4&t=79207#p176746
local shake = {}
shake.__index = shake
local new = function (angle, intensity, duration, speed)
self = {
angle = angle,
intensity = intensity,
duration = duration,
@pablomayobre
pablomayobre / instructions.md
Last active August 29, 2015 14:16
This script turns a style.css generated by icomoon into a lua table with the UTF-8 strings for each icon

In order to use this lib:

  • Go to the Icomoon app
  • Select your icons (you can use a selection.json file with the button)
  • Click on the "Font" button
  • Set your preferences to:
  • Class Prefix = icon-
  • Class Postfix = ``
  • Css Selector = "Use i (for selecting )"
  • Set your Codes to Basic Latin
  • Download
@pablomayobre
pablomayobre / printf.lua
Created January 20, 2015 03:52
A custom prinft for LÖVE which wraps words in the right way while long words get character wrapped
local sub,len,find = string.sub, string.len, string.find
local function getLine(line,text,lBeg,lEnd)
line[#line + 1] = sub(text,lBeg, lEnd)
return lEnd + 1
end
local function wordwrapping(text,limit,f)
local st = "Width of letter '%s' is %dpx, greater than the wrapping width of %dpx.\nIncrease the wrapping width!"
local line, lBeg, lEnd = {}, 0, 0
@pablomayobre
pablomayobre / sequences.lua
Created January 9, 2015 21:49
Trigger functions after a predefined sequence of keys have been pressed (LÖVE)
------Copyright 2015 Pablo A. Mayobre------
--Licensed under the terms of MIT Lincense--
local seq = {}
local split = function (text,pat)
local t = {}
while true do
local pos1, pos2 = text:find(pat, 1, true)
if not pos1 then
@pablomayobre
pablomayobre / m.lua
Last active August 29, 2015 14:12
A math lib used specially in games
------Copyright 2014 Pablo A. Mayobre------
--Licensed under the terms of MIT License--
--[[
math = require "m"
]]
local oldmath = math
local m = math
@pablomayobre
pablomayobre / compile.bat
Last active August 29, 2015 14:12
Is my suite of .bat files created to be used with LÖVE
@echo off
set PATH=%PATH%;"D:\Program Files\7zip\"
set PAR=%~dp0
cd %1
7za a -tzip %~n1.love *
cd %PAR%
move %1\%~n1.love %PAR%
@pablomayobre
pablomayobre / errors.lua
Last active August 29, 2015 14:12
LÖVE Error handler and Notepad++
--No credit nor license is required for this function
--It is based on the original code by LÖVE developers
--Just minor functionality was added, if at all.
return function (src)
local dir = string.gsub(src,"([\\])","/")
local src = dir:match("/$") and dir or (dir.."/")
function love.errhand(msg)
msg = tostring(msg)
@pablomayobre
pablomayobre / require.lua
Last active August 29, 2015 14:12
Some extensions to require
--Copyright Pablo Ariel Mayobre 2014--
------Licensed under MIT License------
local r = {}
local oldrequire = require
local unpack = unpack or table.unpack
local dirandpath = function (dir)
local dir = dir:gsub("/",".")
dir = dir:match("%.$") and string.sub(dir,1,-2) or dir
@pablomayobre
pablomayobre / utf8.lua
Last active August 29, 2015 14:11 — forked from markandgo/utf8.lua
-- $Id: utf8.lua 179 2009-04-03 18:10:03Z pasta $
--
-- Provides UTF-8 aware string functions implemented in pure lua:
-- * string.utf8len(s)
-- * string.utf8sub(s, i, j)
-- * string.utf8reverse(s)
-- * string.utf8char(unicode)
-- * string.utf8unicode(s, i, j)
-- * string.utf8gensub(s, sub_len)
--