this simple beginning of a c/js form validator produces strange strings on the js platform
import strutils
type
Error* {.exportc.} = enum
NoError, InvalidError
Valid* {.exportc.} = object
value: cstring
error: cstring
errorCode: Error
proc valid*(str: string): Valid {.exportc.} =
if "@" in str:
return Valid(value: str, error: "", errorCode: NoError)
else:
return Valid(value: str, error: "email must contain '@'", errorCode: InvalidError)
when isMainModule:
echo valid("peter")
echo valid("[email protected]")
# nim c -r validator.nim
(value: "peter", error: "email must contain \'@\'", errorCode: InvalidError)
(value: "[email protected]", error: "", errorCode: NoError)
# chrome console
(value: "peter", error: "email must contain \'@\'", errorCode: InvalidError)
(value: "[email protected]", error: "", errorCode: NoError)
# but when invoked manually:
a = valid("foo")
{value: "%0f%0o%0o", error: "email must contain '@'", errorCode: 1}
a.value
"%0f%0o%0o"