Add Integer function to convert strings and floats to integers
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from smnp.module import system, mic, note, iterable, sound, synth, string, util
|
from smnp.module import system, mic, note, iterable, sound, synth, string, util, integer
|
||||||
|
|
||||||
functions = [ *system.functions, *mic.functions, *note.functions, *iterable.functions, *sound.functions, *synth.functions, *string.functions, *util.functions ]
|
functions = [ *system.functions, *mic.functions, *note.functions, *iterable.functions, *sound.functions, *synth.functions, *string.functions, *util.functions, *integer.functions ]
|
||||||
methods = [ *system.methods, *mic.methods, *note.methods, *iterable.methods, *sound.methods, *synth.methods, *string.methods, *util.methods ]
|
methods = [ *system.methods, *mic.methods, *note.methods, *iterable.methods, *sound.methods, *synth.methods, *string.methods, *util.methods, *integer.methods ]
|
||||||
4
smnp/module/integer/__init__.py
Normal file
4
smnp/module/integer/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
from smnp.module.integer.function import integer
|
||||||
|
|
||||||
|
functions = [ integer.function ]
|
||||||
|
methods = []
|
||||||
0
smnp/module/integer/function/__init__.py
Normal file
0
smnp/module/integer/function/__init__.py
Normal file
25
smnp/module/integer/function/integer.py
Normal file
25
smnp/module/integer/function/integer.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
from smnp.function.model import CombinedFunction, Function
|
||||||
|
from smnp.function.signature import signature
|
||||||
|
from smnp.type.model import Type
|
||||||
|
from smnp.type.signature.matcher.type import ofType
|
||||||
|
|
||||||
|
_signature1 = signature(ofType(Type.FLOAT))
|
||||||
|
def _function1(env, value):
|
||||||
|
return Type.integer(int(value.value))
|
||||||
|
|
||||||
|
|
||||||
|
_signature2 = signature(ofType(Type.STRING))
|
||||||
|
def _function2(env, value):
|
||||||
|
return Type.integer(int(value.value))
|
||||||
|
|
||||||
|
|
||||||
|
_signature3 = signature(ofType(Type.INTEGER))
|
||||||
|
def _function3(env, value):
|
||||||
|
return value
|
||||||
|
|
||||||
|
function = CombinedFunction(
|
||||||
|
'Integer',
|
||||||
|
Function(_signature1, _function1),
|
||||||
|
Function(_signature2, _function2),
|
||||||
|
Function(_signature3, _function3),
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user