I've been working on this library to automatically change decimal to hexadecimal, but i've been running into a few problems. The first one being that for some reason when i try to load the library, it returns;
home/test; 1; module 'hex' not found
no field package.preload['hex']
no field package.delayed['hex']
/lib/hex.lua; 3; <name> expected near '='
Here's the code:
hex = {}
local function = hex.toHex(input)
local a = input/16
local b = a/16
local c = b/16
local d = c/16
local e = d/16
local g = input%16
local h = a%16
local i = b%16
local j = c%16
local k = d%16
local l = e%16
if g,h,i,j,k,l < 9 then
if g = 10 then
g = "a"
end
if g = 11 then
g = "b"
end
if g = 12 then
g = "c"
end
if g = 13 then
g = "d"
end
if g = 14 then
g = "e"
end
if g = 15 then
g = "f"
end
if h = 10 then
h = "a"
end
if h = 11 then
h = "b"
end
if h = 12 then
h = "c"
end
if h = 13 then
h = "d"
end
if h = 14 then
h = "e"
end
if h = 15 then
h = "f"
end
if i = 10 then
i = "a"
end
if i = 11 then
i = "b"
end
if i = 12 then
i = "c"
end
if i = 13 then
i = "d"
end
if i = 14 then
i = "e"
end
if i = 15 then
i = "f"
end
if j = 10 then
j = "a"
end
if j = 11 then
j = "b"
end
if j = 12 then
j = "c"
end
if j = 13 then
j = "d"
end
if j = 14 then
j = "e"
end
if j = 15 then
j = "f"
end
if k = 10 then
k = "a"
end
if k = 11 then
k = "b"
end
if k = 12 then
k = "c"
end
if k = 13 then
k = "d"
end
if k = 14 then
k = "e"
end
if k = 15 then
k = "f"
end
if l = 10 then
l = "a"
end
if l = 11 then
l = "b"
end
if l = 12 then
l = "c"
end
if l = 13 then
l = "d"
end
if l = 14 then
l = "e"
end
if l = 15 then
l = "f"
end
local hexnum = tonumber(l..k..j..i..h..g)
return hexnum
end
return hex
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
I've been working on this library to automatically change decimal to hexadecimal, but i've been running into a few problems. The first one being that for some reason when i try to load the library, it returns;
home/test; 1; module 'hex' not found
no field package.preload['hex']
no field package.delayed['hex']
/lib/hex.lua; 3; <name> expected near '='
Here's the code:
hex = {} local function = hex.toHex(input) local a = input/16 local b = a/16 local c = b/16 local d = c/16 local e = d/16 local g = input%16 local h = a%16 local i = b%16 local j = c%16 local k = d%16 local l = e%16 if g,h,i,j,k,l < 9 then if g = 10 then g = "a" end if g = 11 then g = "b" end if g = 12 then g = "c" end if g = 13 then g = "d" end if g = 14 then g = "e" end if g = 15 then g = "f" end if h = 10 then h = "a" end if h = 11 then h = "b" end if h = 12 then h = "c" end if h = 13 then h = "d" end if h = 14 then h = "e" end if h = 15 then h = "f" end if i = 10 then i = "a" end if i = 11 then i = "b" end if i = 12 then i = "c" end if i = 13 then i = "d" end if i = 14 then i = "e" end if i = 15 then i = "f" end if j = 10 then j = "a" end if j = 11 then j = "b" end if j = 12 then j = "c" end if j = 13 then j = "d" end if j = 14 then j = "e" end if j = 15 then j = "f" end if k = 10 then k = "a" end if k = 11 then k = "b" end if k = 12 then k = "c" end if k = 13 then k = "d" end if k = 14 then k = "e" end if k = 15 then k = "f" end if l = 10 then l = "a" end if l = 11 then l = "b" end if l = 12 then l = "c" end if l = 13 then l = "d" end if l = 14 then l = "e" end if l = 15 then l = "f" end local hexnum = tonumber(l..k..j..i..h..g) return hexnum end return hex
Sorry it's so long!
Link to post
Share on other sites