Skip to content

Instantly share code, notes, and snippets.

@leandromoreira
Last active April 21, 2020 12:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save leandromoreira/6c1b587c64fc0d0fa9360b736d47c707 to your computer and use it in GitHub Desktop.
-- 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