Skip to content

Instantly share code, notes, and snippets.

View EngineerSmith's full-sized avatar
🔧
🦆

Engineer Smith EngineerSmith

🔧
🦆
View GitHub Profile
local buffer = require("string.buffer")
local serialize = {
encode = function(...)
local data = {}
for i=1, select('#', ...) do
local var = select(i, ...)
if type(var) == "userdata" then
var = var:getString()
end
@EngineerSmith
EngineerSmith / main.lua
Created January 19, 2022 22:05
Hide love2d window using SDL2
if love._version_major == "11" and jit then
local ffi = require("ffi")
ffi.cdef[[
typedef void SDL_Window;
SDL_Window* SDL_GL_GetCurrentWindow(void);
void SDL_HideWindow(SDL_Window * window);
]]
local SDL2 = ffi.load("SDL2")
local window = SDL2.SDL_GL_GetCurrentWindow()
SDL2.SDL_HideWindow(window)
@EngineerSmith
EngineerSmith / main.lua
Last active January 14, 2022 00:06
Hex value to string lua using ffi
local ffi = require("ffi")
ffi.cdef[[
typedef struct {
union {
uint64_t rgba;
struct {
uint8_t a;
uint8_t b;
uint8_t g;
uint8_t r;
local scene = {}
-- all functions are the same as love.* (except scene.unload) but put them in a scene table and return it at the end
scene.load = function()
scene.img = love.graphics.newImage("logo.png")
end
scene.unload = function() -- only custom function added, called before switching scenes
scene.img = nil -- unload image when leaving the scene as we will never return back to this splash screen
-- if you're switching between the game and another scene back and forth you won't need to keep loading the images
-- therefore check if they're already loaded in `scene.load` otherwise you will be
@EngineerSmith
EngineerSmith / lua.reg
Created November 15, 2021 21:56
Add .lua to File Explorer context menu in windows 10
Windows Registry Editor Version 5.00
; new file type
[HKEY_CLASSES_ROOT\.lua]
@="lua"
; template
[HKEY_CLASSES_ROOT\.lua\ShellNew]
"FileName"=""
@EngineerSmith
EngineerSmith / main.lua
Last active February 21, 2022 14:41
Pinch and zoom + pan in love2d
local lg, lt = love.graphics, love.touch
local insert, remove = table.insert, table.remove
local sqrt = math.sqrt
local x,y, w,h = love.window.getSafeArea()
local textW, textH = x+w,y+h
local a, b = textW/2, textH/2
local texture = lg.newCanvas(textW,textH)
lg.setCanvas(texture)
lg.setColor(.5,.5,.5)
local pixelArt = function(asset)
asset:setFilter("nearest","nearest")
end
local assets = {
{"red","assets/red.png",onload=pixelArt},
{"red","assets/red.png",onload=pixelArt},
}
local maths = {}
function maths.cross(ux, uy, uz, vx, vy, vz)
local nx = (uy*vz) - (uz*vy)
local ny = (uz*vx) - (ux*vz)
local nz = (ux*vy) - (uy*vx)
return nx, ny, nz
end
function maths.dot(ux, uy, uz, vx, vy, vz)
local lily = require("Lib.Lily")
local global = require("Scripts.global")
local file = require("Scripts.Utilities.file")
local insert = table.insert
local lilyLoaders = {
png = "newImage",
jpg = "newImage",
jpeg = "newImage",
local lg = love.graphics
local canvas = lg.newCanvas(128,128) -- treat canvas as your sprite, but I was too lazy to draw a debug image, so I made one from a canvas
lg.setCanvas(canvas) -- French flag debug graphic
lg.clear(1,1,1)
lg.setColor(0.2,0.2,0.8)
lg.rectangle("fill", 0, 0, 43,128)
lg.setColor(0.8,0.2,0.2)
lg.rectangle("fill",88,0, 43,128)
lg.setColor(1,1,1)
lg.setCanvas()