Skip to content

Instantly share code, notes, and snippets.

@leandromoreira
Last active Apr 21, 2020
Embed
What would you like to do?
-- Error during evaluation - syntactically invalid
code, err = loadstring(" a = 1 \n a a \n pring(a) \n")
print(code)
-- nil
print(err)
-- [string " a = 1 ..."]:2: '=' expected near 'a'
-- Error during runtime - syntactically valid
stringcode = " a = taketime.menu "
code, err = loadstring(stringcode)
print(err) -- no evaluation error
-- nil
print(code) -- a runtime error will happen once we execute this function
-- function: 0x40a068a0
function err_handler(err_msg)
print("an err was raised", err_msg)
return err_msg
end
status, ret = xpcall(code, err_handler)
print(status)
-- false
print(ret)
-- [string " a = taketime.menu "]:1: attempt to index global 'taketime' (a nil value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment