- Joined
- Aug 7, 2013
- Messages
- 1,338
Hi,
Can someone give me the Lua version of this python function?
I've lost so much hair trying to turn this into a lua function...
Edit: a lua version
Can someone give me the Lua version of this python function?
I've lost so much hair trying to turn this into a lua function...
Code:
def add(value, baseDigits, result = ""):
if value == "":
value = "0"
if value[-1] != baseDigits[-1]:
next_digit = baseDigits.find(value[-1]) + 1
return value[:-1] + baseDigits[next_digit] + result
else:
return add(value[:-1], baseDigits, result + "0")
Edit: a lua version
Code:
//! i function add(value, result)
//! i if value == "" then
//! i value = "0"
//! i end
//! i lastValue = string.sub(value, string.len(value), string.len(value))
//! i lastBase = string.sub(BASE_62, string.len(BASE_62), string.len(BASE_62))
//! i if lastValue ~= lastBase then
//! i nextBase = string.sub(BASE_62, string.find(BASE_62, lastValue) + 1, string.find(BASE_62, lastValue) + 1)
//! i return string.sub(value, 1, string.len(value) - 1) .. nextBase .. result
//! i else
//! i return add(string.sub(value, 1, string.len(value) - 1), result .. "0")
//! i end
//! i end
Last edited: