String to int conversion. Closes #362.
This commit is contained in:
parent
8d8d696966
commit
0c96dbff3a
|
@ -2019,6 +2019,11 @@ class Interpreter():
|
|||
if method_name == 'startswith':
|
||||
return obj.startswith(s)
|
||||
return obj.endswith(s)
|
||||
elif method_name == 'to_int':
|
||||
try:
|
||||
return int(obj)
|
||||
except Exception:
|
||||
raise InterpreterException('String can not be converted to int: ' + obj)
|
||||
raise InterpreterException('Unknown method "%s" for a string.' % method_name)
|
||||
|
||||
def to_native(self, arg):
|
||||
|
|
|
@ -40,3 +40,5 @@ endif
|
|||
if long.endswith(prefix)
|
||||
error('Not suffix.')
|
||||
endif
|
||||
|
||||
assert('3'.to_int() == 3, 'String int conversion does not work.')
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
project('int conversion', 'c')
|
||||
|
||||
'notanumber'.to_int()
|
Loading…
Reference in New Issue