Enabling Bitwise Operations on Mesecon Luacontrollers in Minetest

Assuming the Mesecon mod is already installed.

minetest-5.7.0-win64\mods\mesecons\mesecons_luacontroller

Go to this location(at least on Windows). Take note of the Minetest version/folder name.

Locate the init.lua file and inside it the function: local function create_environment
You should see a local env and append this:

		bit = {
			tobit = bit.tobit, 
			tohex = bit.tohex, 
			bnot = bit.bnot, 
			band = bit.band, 
			bor = bit.bor, 
			bxor = bit.bxor, 
			lshift = bit.lshift, 
			rshift = bit.rshift, 
			arshift = bit.arshift, 
			rol = bit.rol, 
			ror = bit.ror, 
			bswap = bit.bswap,
		}

After that, local env should look something like this:

	local env = {
		pin = merge_port_states(vports, rports),
		port = vports_copy,
		event = event,
		mem = mem,
		heat = mesecon.get_heat(pos),
		heat_max = mesecon.setting("overheat_max", 20),
		print = safe_print,
		interrupt = get_interrupt(pos, itbl, send_warning),
		digiline_send = get_digiline_send(pos, itbl, send_warning),
		string = {
			byte = string.byte,
			char = string.char,
			format = string.format,
			len = string.len,
			lower = string.lower,
			upper = string.upper,
			rep = safe_string_rep,
			reverse = string.reverse,
			sub = string.sub,
			find = safe_string_find,
		},
		math = {
			abs = math.abs,
			acos = math.acos,
			asin = math.asin,
			atan = math.atan,
			atan2 = math.atan2,
			ceil = math.ceil,
			cos = math.cos,
			cosh = math.cosh,
			deg = math.deg,
			exp = math.exp,
			floor = math.floor,
			fmod = math.fmod,
			frexp = math.frexp,
			huge = math.huge,
			ldexp = math.ldexp,
			log = math.log,
			log10 = math.log10,
			max = math.max,
			min = math.min,
			modf = math.modf,
			pi = math.pi,
			pow = math.pow,
			rad = math.rad,
			random = math.random,
			sin = math.sin,
			sinh = math.sinh,
			sqrt = math.sqrt,
			tan = math.tan,
			tanh = math.tanh,
		},
		table = {
			concat = table.concat,
			insert = table.insert,
			maxn = table.maxn,
			remove = table.remove,
			sort = table.sort,
		},
		os = {
			clock = os.clock,
			difftime = os.difftime,
			time = os.time,
			datetable = safe_date,
		},
		bit = {
			tobit = bit.tobit, 
			tohex = bit.tohex, 
			bnot = bit.bnot, 
			band = bit.band, 
			bor = bit.bor, 
			bxor = bit.bxor, 
			lshift = bit.lshift, 
			rshift = bit.rshift, 
			arshift = bit.arshift, 
			rol = bit.rol, 
			ror = bit.ror, 
			bswap = bit.bswap,
		}
	}

You can now use the functions: bit.tobit, bit.band, bit.rol, etc.

Notes:
Anyway, here’s a Mesecon Luacontroller tutorial.
Probably install the Digilines mod too. So you can use the digiline_send(channel, msg) function. (Digilines tutorial)