Pinkstack/roblox-luau-corpus-text huggingface dataset:
-- Death Messages - Message handler @ JDLENL 3/22/20
-- Please consider accrediting me in the description! It'd be nice of you.
-- This is the part that shows the death messages in chat



game:GetService("ReplicatedStorage"):WaitForChild("DeathMessage").OnClientEvent:Connect(function(Message)
	local s = game:GetService("StarterGui")
	s:SetCore("ChatMakeSystemMessage",{
		Text = Message;
		-- you can change the death message color here: default = red
		Color = Color3.new(1,.2,0);
	})
end)
--Rainbow Sparkling Trail--



local function AttachParticleControl(source_part)
	
	local prtc = nil
	
	local function Start()
		prtc = script.Sparkle:clone()
		prtc.Parent = source_part
	end
	
	local function Update()
		
	end
	
	local function Stop()
		if prtc ~= nil then
			prtc:destroy()
			prtc = nil
		end
	end
	
	return {Start = Start, Update = Update, Stop = Stop}
end

return AttachParticleControl
-- ROBLOX DEVIATION: Ignore enableComponentStackLocations
-- local ReactFeatureFlags = require(script.Parent.ReactFeatureFlags)
-- local enableComponentStackLocations = ReactFeatureFlags.enableComponentStackLocations



local ReactSymbols = require(script.Parent.ReactSymbols)
local REACT_SUSPENSE_TYPE = ReactSymbols.REACT_SUSPENSE_TYPE
local REACT_SUSPENSE_LIST_TYPE = ReactSymbols.REACT_SUSPENSE_LIST_TYPE
local REACT_FORWARD_REF_TYPE = ReactSymbols.REACT_FORWARD_REF_TYPE
local REACT_MEMO_TYPE = ReactSymbols.REACT_MEMO_TYPE
local REACT_BLOCK_TYPE = ReactSymbols.REACT_BLOCK_TYPE
local REACT_LAZY_TYPE = ReactSymbols.REACT_LAZY_TYPE

local ConsolePatchingDev = require(script.Parent["ConsolePatchingDev.roblox"])
local disableLogs = ConsolePatchingDev.disableLogs
local reenableLogs = ConsolePatchingDev.reenableLogs

local ReactSharedInternals = require(script.Parent.ReactSharedInternals)
local ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher
-- events



REMOTES.Melee.OnServerEvent:connect(function(player, action, item, ...)
	local character	= player.Character
	if character then
		local equipped	= character.Equipped.Value
		
		if item == equipped then
			if action == "Init" then
				local index		= ...
				local animation	= item.Animations["Attack" .. tostring(index)]
				local timeout	= 0
				
				repeat
					RunService.Stepped:wait()
					for _, track in pairs(character.Humanoid:GetPlayingAnimationTracks()) do
						if track.Animation.AnimationId == animation.AnimationId then
							if track.Length == 0 then
								repeat RunService.Stepped:wait() until track.Length ~= 0
							end
							timeout	= track.Length
							break
						end
					end
				until timeout ~= 0
				
				Init(player, item, timeout)
				
				for _, p in pairs(Players:GetPlayers()) do
					if p ~= player then
						REMOTES.Effect:FireClient(p, "Swing", item, timeout)
					end
				end
			elseif action == "Hit" then
				local info	= inits[player]
				if info then
					if info.Item == item then
						if tick() <= info.Timeout then
							local humanoid	= ...
							if DAMAGE:PlayerCanDamage(player, humanoid) then
								local otherChar	= humanoid.Parent
								local config	= require(item.Config)
								
								local offset	= otherChar.HumanoidRootPart.Position - character.HumanoidRootPart.Position
								local distance	= offset.Magnitude
								
								if distance < MAX_DISTANCE then
									if humanoid.Health > 0 then
										local down	= humanoid:FindFirstChild("Down")
										local alreadyDowned	= false
										
										if down then
											alreadyDowned	= down.Value
										end
										
										local damage	= config.Damage
										DAMAGE:Damage(humanoid, damage, player)
										otherChar.HumanoidRootPart.Velocity	= otherChar.HumanoidRootPart.Velocity + offset.Unit * config.Knockback
										
										local otherPlayer	= Players:GetPlayerFromCharacter(humanoid.Parent)
										if otherPlayer then
											REMOTES.HitIndicator:FireClient(otherPlayer, offset, damage)
										end
										
										if humanoid.Health <= 0 then
											local killDist	= math.floor(offset.Magnitude + 0.5)
											STAT_SCRIPT.FurthestKill:Fire(player, killDist)
											REMOTES.Killfeed:FireAllClients(player.Name, humanoid.Parent.Name, item.Name, killDist)
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
end)

Players.PlayerRemoving:connect(function(player)
	if inits[player] then
		inits[player]	= nil
	end
end)
-------------------------------



local tool = script.Parent
local player = game.Players.LocalPlayer
while player.Character == nil do wait() end
local char = player.Character
while char:FindFirstChild("Humanoid") == nil do wait() end
local hum = char:FindFirstChild("Humanoid")

local enabled = true
local equipped = false
local ischarging = false
local Config = tool:FindFirstChild("Config")
local Direction = Config:FindFirstChild("Direction")
Direction.Value = "Up"

tool.Selected:connect(function(mouse)
	equipped = true
	mouse.Icon = "rbxasset://textures\\GunCursor.png"
	mouse.Button1Down:connect(function()
		if not enabled then return end
		if hum == nil then return end
		if hum.Health <= 0 then return end
		if mouse == nil then return end
		if not ischarging then
			ischarging = true
			enabled = false
			script.Parent.ReleaseProjectile:FireServer(mouse.Hit.p)
			mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
			wait(RELOAD_TIME)
			mouse.Icon = "rbxasset://textures\\GunCursor.png"
			enabled = true
			ischarging = false
		end
	end)
	mouse.KeyDown:connect(function(key)
		key = key:lower()
		if key == "q" then
			if Direction.Value == "Up" then
				Direction.Value = "Down"
			elseif Direction.Value == "Down" then
				Direction.Value = "Left"
			elseif Direction.Value == "Left" then
				Direction.Value = "Right"
			elseif Direction.Value == "Right" then
				Direction.Value = "Up"
			end
		elseif key == "e" then
			if Direction.Value == "Up" then
				Direction.Value = "Right"
			elseif Direction.Value == "Right" then
				Direction.Value = "Left"
			elseif Direction.Value == "Left" then
				Direction.Value = "Down"
			elseif Direction.Value == "Down" then
				Direction.Value = "Up"
			end
		end
	end)
end)

tool.Deselected:connect(function(mouse)
	equipped = false
end)
--[[
	AntiGravityCoil
	Tool that isn't Tree'd
	Phoenix
]]



local Tool = script.Parent 
local Player = Tool.Parent.Parent
local Died = nil
local Equipped = false

local IsAlive = function()
	if Player.Character then
		if Player.Character:FindFirstChild("Humanoid") then
			if Player.Character:FindFirstChild("Humanoid").Health > 0 then
				return true
			end
		end
	end

	return false
end


local Humanoid = function()
	if Player.Character then
		if Player.Character:FindFirstChild("Humanoid") then
			return Player.Character:FindFirstChild("Humanoid")
		end
	end
end


local Weld = function(From, To)
	local WeldIns = Instance.new("WeldConstraint")
	WeldIns.Part0 = From
	WeldIns.Part1 = To
	WeldIns.Parent = From
	WeldIns.Name = "Weld"
end

local Welding = function(WeldTree, OverrideCenter)
	local Center = nil
	
	if OverrideCenter == nil then
		if WeldTree:FindFirstChildOfClass("MeshPart") then
			Center = WeldTree:FindFirstChildOfClass("MeshPart")
		elseif WeldTree:FindFirstChildOfClass("Part") then
			Center = WeldTree:FindFirstChildOfClass("Part")
		elseif WeldTree:FindFirstChildOfClass("UnionOperation") then
			Center = WeldTree:FindFirstChildOfClass("UnionOperation")
		end
	else
		Center = OverrideCenter
	end

	if Center ~= nil then
		for Index, ToWeld in pairs(WeldTree:GetDescendants()) do
			if ToWeld:IsA("BasePart") then
				Weld(ToWeld, Center)
			end
		end
	else
		print("Could not get a part to weld to! Attempted ".. tostring(WeldTree:GetFullName()).. " By: ".. script:GetFullName())
	end
end


local Enable = function()
	game:GetService("ServerScriptService").Server.Events.ZGSet:Fire(Player, true, false)
end


local Disable = function()
	game:GetService("ServerScriptService").Server.Events.ZGSet:Fire(Player, false, false)
end


Tool.Equipped:Connect(function()
	if Equipped == true then
		return
	end
	
	if IsAlive() == true then
		Equipped = true
		
		Died = Humanoid().Died:Connect(function()
			Disable()
			Died:Disconnect()
			Died = nil
		end)

		Enable()

		Tool.Handle.CoilSound:Play()
	end
end)

Tool.Unequipped:Connect(function()
	if Equipped == false then
		return
	end
	
	Equipped = false
	
	if Died ~= nil then
		Died:Disconnect()
		Died = nil
	end

	Disable()
end)

Welding(Tool.Model, Tool.Handle)
-- FIXME: This should be updated to be closer to the actual
-- `Object.preventExtensions` functionality in JS. This requires additional
-- support from the VM


local function preventExtensions<T>(t: T & (Object | Array<any>)): T
	local name = tostring(t)

	return (
		setmetatable(t :: any, {
			__newindex = function(self, key, value)
				local message = ("%q (%s) is not a valid member of %s"):format(tostring(key), typeof(key), name)

				error(message, 2)
			end,
			__metatable = false,
		}) :: any
	) :: T
end

return preventExtensions
--[[Engine]]


	--Torque Curve
	Tune.Horsepower		= 505		--	[TORQUE CURVE VISUAL]
	Tune.IdleRPM		= 700		--		https://www.desmos.com/calculator/2uo3hqwdhf
	Tune.PeakRPM		= 6000		--		Use sliders to manipulate values
	Tune.Redline		= 6700		--		Copy and paste slider values into the respective tune values
	Tune.EqPoint		= 5500
	Tune.PeakSharpness	= 7.5
	Tune.CurveMult		= 0.16
	
	--Incline Compensation
	Tune.InclineComp	= 1.7			-- Torque compensation multiplier for inclines (applies gradient from 0-90 degrees)
	
	--Misc
	Tune.RevAccel		= 150		-- RPM acceleration when clutch is off
	Tune.RevDecay		= 75		-- RPM decay when clutch is off
	Tune.RevBounce		= 500		-- RPM kickback from redline
	Tune.IdleThrottle	= 3			-- Percent throttle at idle
	Tune.ClutchTol		= 500		-- Clutch engagement threshold (higher = faster response)
-- Variables that will be used globally (throughout) the script
-- Services


local TweenService = game:GetService("TweenService")
local ContextActionService = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
------------------------------------------------------------------------
-- returns a suitably-formatted chunk name or id
-- * from lobject.c, used in llex.c and ldebug.c
-- * the result, out, is returned (was first argument)
------------------------------------------------------------------------


function luaX:chunkid(source, bufflen)
  local out
  local first = string.sub(source, 1, 1)
  if first == "=" then
    out = string.sub(source, 2, bufflen)  -- remove first char
  else  -- out = "source", or "...source"
    if first == "@" then
      source = string.sub(source, 2)  -- skip the '@'
      bufflen = bufflen - #" '...' "
      local l = #source
      out = ""
      if l > bufflen then
        source = string.sub(source, 1 + l - bufflen)  -- get last part of file name
        out = out.."..."
      end
      out = out..source
    else  -- out = [string "string"]
      local len = string.find(source, "[\n\r]")  -- stop at first newline
      len = len and (len - 1) or #source
      bufflen = bufflen - #(" [string \"...\"] ")
      if len > bufflen then len = bufflen end
      out = "[string \""
      if len < #source then  -- must truncate?
        out = out..string.sub(source, 1, len).."..."
      else
        out = out..source
      end
      out = out.."\"]"
    end
  end
  return out
end
--m3.Volume = 0


m2.Looped = false
m2.Playing = false
script.Parent.Parent:WaitForChild("Drive").Locotrol.Event:connect(function(data)
	if data["Horn"] == true then
		m2.Volume = 0
		m2.Looped = false
		m2:Stop()
		m2.Playing = false
		--m3.Volume = 0
		--m3.Stop()
		m1.Volume = 1
		m1:Play()
		--wait(m1.TimeLength) --disabled because it makes looping part stuck playing if stopped too soon.
		if m1.TimePosition < m1.TimeLength then
			m2.Looped = true
			m2.Volume = 1
			m2:Play()
		else
			m1.Volume = 0
			m1:Stop()
		end
	elseif data["Horn"] == false then
		m1.Volume = 0
		m1:Stop()
		--[[ --For 3 part option
		m2.Volume = 0
		m2:Stop()
		m2.Looped = false
		m2.Playing = false
		m3.Volume = 1
		m3:Play()
		--]]
		----[[ -- For 2 part option
		if m2.IsPlaying == true then
			for i=1, 0, -.1 do
				m2.Volume = i*1
				wait(.1)
			end
		end
		m2.Volume = 0
		m2.Looped = false
		m2.Playing = false
		m2:Stop()
		----]]	
	end
end)
--Main function


local function AttachAuraControl(source_part, eff_cont) --(source_part, effect_container)
	
	local AnimObj
	
	local function Start()
		AnimObj = {}
		AnimObj["LastUpdate"] = tick()
		
		AnimObj["Parts"] = {}
		
		for i = 1, 10 do
			local np = EFFECT_LIB.NewInvisiblePart()
			np.Transparency = 0.5
			np.Material = "Neon"
			np.BrickColor = BrickColor.new("Institutional white")
			
			local knife_mesh = Instance.new("BlockMesh")
			knife_mesh.Scale = Vector3.new(8, 2, 2)
			knife_mesh.Parent = np
			
			AnimObj["Parts"][i] = np
	
			np.Parent = eff_cont
		end
	end
	
	local function Update()
		local loop = EFFECT_LIB.Loop(6)
		
		for i = 1, #AnimObj["Parts"] do
			AnimObj["Parts"][i].CFrame = source_part.CFrame * CFrame.Angles(0, 0, math.rad(loop * 360 + (360 / #AnimObj["Parts"] * (i - 1)))) * CFrame.new(-3, 0, 1.5)
		end
	end
	
	local function Stop()
		eff_cont:ClearAllChildren()
		AnimObj = nil
	end
	
	return {Start = Start, Update = Update, Stop = Stop}
end

return AttachAuraControl
-- UAEmaple





function onTouch(part) 
local human = part.Parent:findFirstChild("Humanoid") 
if human ~= nil then 
part.Parent:findFirstChild("Head").Transparency = 1 
part.Parent:findFirstChild("Torso").Transparency = 1 
part.Parent:findFirstChild("Left Arm").Transparency = 1 
part.Parent:findFirstChild("Right Arm").Transparency = 1 
part.Parent:findFirstChild("Left Leg").Transparency = 1 
part.Parent:findFirstChild("Right Leg").Transparency = 1 
if part.Parent:findFirstChild("Head"):findFirstChild("face") == nil then return end 
part.Parent:findFirstChild("Head"):findFirstChild("face"):remove() 
if part.Parent:findFirstChild("Torso"):findFirstChild("roblox") == nil then return end 
part.Parent:findFirstChild("Torso"):findFirstChild("roblox"):remove() 
end 
end 
script.Parent.Touched:connect(onTouch)
--Touch Controls
--I wanted to use the MasterControl module, but the rules for the magnitude of GetMoveVector()
--seem arbitary and unclear, so it's hooked into the ui itself. 


function RunTouchControls()
	local TouchGui = Player.PlayerGui:FindFirstChild("TouchGui")
	local StickOuter = TouchGui.TouchControlFrame.ThumbstickFrame.OuterImage
	local StickInner = TouchGui.TouchControlFrame.ThumbstickFrame.StickImage
	local CenterX = StickOuter.Size.X.Offset/2 - StickInner.Size.X.Offset/2
	local MinX = CenterX - StickOuter.Size.X.Offset/2
	local MaxX = CenterX + StickOuter.Size.X.Offset/2
	local CenterY = StickOuter.Size.Y.Offset/2 - StickInner.Size.Y.Offset/2
	local MinY = CenterY - StickOuter.Size.Y.Offset/2
	local MaxY = CenterY + StickOuter.Size.Y.Offset/2
	while Input.InputMode == "Touch" do
		wait()
		local X = ((StickInner.Position.X.Offset-MinX) / (MaxX-MinX))*2  - 1 
		local Y = ((StickInner.Position.Y.Offset-MinY) / (MaxY-MinY))*-2  + 1 
		Input.LStickX = -X
		Input.LStickY = Y
	end
end
--- Returns a table containing the parsed values for all of the arguments.


function Command:GatherArgumentValues ()
	local values = {}

	for i = 1, #self.ArgumentDefinitions do
		local arg = self.Arguments[i]
		if arg then
			values[i] = arg:GetValue()
		else
			values[i] = self.ArgumentDefinitions[i].Default
		end
	end

	return values
end
--Listen for new seats


Remotes.NewSeat.OnClientEvent:Connect(function(Seat)
	print("Seat add received")
	Seats[Seat] = Seat
	Seat.AncestryChanged:connect(function()
		if not Seat:IsDescendantOf(game) then
			--Removed
			Seats[Seat] = nil
		end
	end)
end)
-- 	local function deletePropertyWin32(_target: unknown, key: unknown)
-- 		error("not implemented") --[[ ROBLOX TODO: Unhandled node for type: ForInStatement ]] --[[ for (const name in real) {
--       if (real.hasOwnProperty(name)) {
--         if (typeof key === 'string') {
--           if (name.toLowerCase() === key.toLowerCase()) {
--             delete real[name];
--             delete lookup[name.toLowerCase()];
--           }
--         } else {
--           if (key === name) {
--             delete real[name];
--             delete lookup[name];
--           }
--         }
--       }
--     } ]]
-- << Raycasting functions >>--


function cross(vector1, vector2)
	return Vector3.new(vector1.y * vector2.z - vector2.y * vector1.z, vector1.z * vector2.x - vector1.x * vector2.z, vector1.x * vector2.y - vector2.x * vector1.y)
end
function dot(vector1, vector2)
	return (vector1.x * vector2.x + vector1.y * vector2.y + vector1.z * vector2.z)
end
function getLineSphereCollide(linePoint1, lineVector, sphereCenter, radius)
	local a = lineVector.x * lineVector.x + lineVector.y * lineVector.y + lineVector.z * lineVector.z
	local b = lineVector.x * (linePoint1.x - sphereCenter.x) + lineVector.y * (linePoint1.y - sphereCenter.y) + lineVector.z * (linePoint1.z - sphereCenter.z)
	local c = (linePoint1.x - sphereCenter.x) * (linePoint1.x - sphereCenter.x) + (linePoint1.y - sphereCenter.y) * (linePoint1.y - sphereCenter.y) + (linePoint1.z - sphereCenter.z) * (linePoint1.z - sphereCenter.z) - radius * radius
	if (a > 0) and (b * b >= a * c) then
		local diff = math.sqrt(b * b - a * c)
		return ((-b - diff) / a), ((diff - b) / a)
	else
		return -1, -1
	end
end
-- run this code in the command bar: (view -> command bar)



starterPack = workspace["Terrain Pickaxe Kit v1.0"]["Ungroup in StarterPack"]:GetChildren()
for i, v in pairs(starterPack) do
	v.Parent = game.StarterPack
end

starterGui = workspace["Terrain Pickaxe Kit v1.0"]["Ungroup in StarterGui"]:GetChildren()
for i, v in pairs(starterGui) do
	v.Parent = game.StarterGui
end

serverScriptService = workspace["Terrain Pickaxe Kit v1.0"]["Ungroup in ServerScriptService"]:GetChildren()
for i, v in pairs(serverScriptService) do
	v.Parent = game.ServerScriptService
end

workspace["Terrain Pickaxe Kit v1.0"].Notes.Parent = workspace
workspace["Terrain Pickaxe Kit v1.0"]:Destroy()

warn("Setup successful, notes have been moved to workspace")
--//Toggle event//--


script.Parent.Door.MainDoor.ClickDetector.MouseClick:Connect(function()
	if DoorStatus == "Closed" and Debounce == false then
		Debounce = true
		DoorMain.Open:Play()
		Door.HandleUno.HingeConstraint.TargetAngle=70
		Door.HandleDos.HingeConstraint.TargetAngle=-70
		TweenModel(script.Parent.Door, TGP)
		Door.HandleUno.HingeConstraint.TargetAngle=0
		Door.HandleDos.HingeConstraint.TargetAngle=0
		DoorStatus = "Opened"
		Debounce = false
	elseif DoorStatus == "Opened" and Debounce == false then
		Debounce = true
		DoorMain.Close:Play()
		TweenModel(script.Parent.Door, OrigPos)
		DoorStatus = "Closed"
		Debounce = false
	end
	end)
--Brakes = {} --Removed the unused brake functionality


Horn = false
Bell = false
Engine = false
Lights = false
Lights2 = false
Lights3 = false
Lights4 = false
BellPersistsAfterLeaving = true
FrontCoupler = {
	model = nil,
	coupledto = nil,
	weld = nil,
	drive = nil,
	front = true,
	Reversed = false,
	GetControls = nil,
	WeldRemoved = nil,
	LastUpdate = 0,
}
RearCoupler = {
	model = nil,
	coupledto = nil,
	weld = nil,
	drive = nil,
	front = false,
	Reversed = false,
	GetControls = nil,
	WeldRemoved = nil,
	LastUpdate = 0,
}
cplrstr = nil
SeatWeld = nil
Front = seat.Parent.Front
MAXIMUMSPEED=seat.MaxSpeed
TORQUE=seat.Torque
-- Constructor/Destructor


function WaypointPath.new(player, startPos, endPos)
	local self = setmetatable({}, WaypointPath)

	-- Player variables
	self.player = player
	self.character = player.Character or player.CharacterAdded:wait()
	self.humanoid = self.character:WaitForChild("Humanoid")
	self.humanoidRoot = self.character.HumanoidRootPart
	
	-- Create the path object
	self.path = PathfindingService:CreatePath()
	
	-- Compute the path
	self.path:ComputeAsync(startPos, endPos)
	
	-- Get the path waypoints
	self.waypoints = self.path:GetWaypoints()
	
	self.currentIndex = 2
	self.count = 1
	
	self._WaypointReachedEvent = Instance.new("BindableEvent")
	self.WaypointReached = self._WaypointReachedEvent.Event
	
	self._NodeReachedEvent = Instance.new("BindableEvent")
	self.NodeReached = self._NodeReachedEvent.Event
	
	self._FinishedMovingEvent = Instance.new("BindableEvent")
	self.FinishedMoving = self._FinishedMovingEvent.Event
	
	return self
end

function WaypointPath:Destroy()
	self._WaypointReachedEvent:Destroy()
	
	self._WaypointReachedEvent:Destroy()
	self._NodeReachedEvent:Destroy()
	self._FinishedMovingEvent:Destroy()
end
--[[
	Updates the value stored in this State object.

	If `force` is enabled, this will skip equality checks and always update the
	state object and any dependents - use this with care as this can lead to
	unnecessary updates.
]]


function class:set(newValue: any, force: boolean?)
	-- if the value hasn't changed, no need to perform extra work here
	if self._value == newValue and not force then
		return
	end

	self._value = newValue

	-- update any derived state objects if necessary
	updateAll(self)
end

local function State(initialValue: any)
	local self = setmetatable({
		type = "State",
		kind = "State",
		-- if we held strong references to the dependents, then they wouldn't be
		-- able to get garbage collected when they fall out of scope
		dependentSet = setmetatable({}, WEAK_KEYS_METATABLE),
		_value = initialValue
	}, CLASS_METATABLE)

	initDependency(self)

	return self
end

return State
-- ok?  probably not if running on a 32-bit int Lua number type platform


function M.tobit(x)
  return x % 2^32
end

M.cast = M.tobit

M.bxor = make_bitop {[0]={[0]=0,[1]=1},[1]={[0]=1,[1]=0}, n=4}
local bxor = M.bxor

function M.bnot(a)   return MODM - a end
local bnot = M.bnot

function M.band(a,b) return ((a+b) - bxor(a,b))/2 end
local band = M.band

function M.bor(a,b)  return MODM - band(MODM - a, MODM - b) end
local bor = M.bor

local lshift, rshift -- forward declare

function M.rshift(a,disp) -- Lua5.2 insipred
  if disp < 0 then return lshift(a,-disp) end
  return floor(a % 2^32 / 2^disp)
end
rshift = M.rshift

function M.lshift(a,disp) -- Lua5.2 inspired
  if disp < 0 then return rshift(a,-disp) end 
  return (a * 2^disp) % 2^32
end
lshift = M.lshift

function M.tohex(x, n) -- BitOp style
  n = n or 8
  local up
  if n <= 0 then
    if n == 0 then return '' end
    up = true
    n = - n
  end
  x = band(x, 16^n-1)
  return ('%0'..n..(up and 'X' or 'x')):format(x)
end
local tohex = M.tohex

function M.extract(n, field, width) -- Lua5.2 inspired
  width = width or 1
  return band(rshift(n, field), 2^width-1)
end
local extract = M.extract

function M.replace(n, v, field, width) -- Lua5.2 inspired
  width = width or 1
  local mask1 = 2^width-1
  v = band(v, mask1) -- required by spec?
  local mask = bnot(lshift(mask1, field))
  return band(n, mask) + lshift(v, field)
end
local replace = M.replace

function M.bswap(x)  -- BitOp style
  local a = band(x, 0xff); x = rshift(x, 8)
  local b = band(x, 0xff); x = rshift(x, 8)
  local c = band(x, 0xff); x = rshift(x, 8)
  local d = band(x, 0xff)
  return lshift(lshift(lshift(a, 8) + b, 8) + c, 8) + d
end
local bswap = M.bswap

function M.rrotate(x, disp)  -- Lua5.2 inspired
  disp = disp % 32
  local low = band(x, 2^disp-1)
  return rshift(x, disp) + lshift(low, 32-disp)
end
local rrotate = M.rrotate

function M.lrotate(x, disp)  -- Lua5.2 inspired
  return rrotate(x, -disp)
end
local lrotate = M.lrotate

M.rol = M.lrotate  -- LuaOp inspired
M.ror = M.rrotate  -- LuaOp insipred


function M.arshift(x, disp) -- Lua5.2 inspired
  local z = rshift(x, disp)
  if x >= 0x80000000 then z = z + lshift(2^disp-1, 32-disp) end
  return z
end
local arshift = M.arshift

function M.btest(x, y) -- Lua5.2 inspired
  return band(x, y) ~= 0
end