Functions and lambdas in OSL are defined using the function or def keyword with parameter syntax and a body.
function
def
myFunc = function(params) -> ( body ) myFunc = def(params) -> ( body )
params: Parameter names (can be zero or more, comma-separated)
params
body: The function body containing the logic to execute
body
Returns a callable function object.
add10 = def(v) -> ( v + 10 ) log add10(5) // 15
Both function and def keywords work identically for defining lambdas
The arrow -> separates parameters from the body
->
The body can be a single expression or multiple statements in parentheses
Functions are first-class values and can be passed as arguments or stored in variables
Last updated 20 days ago
add = def(a, b) -> ( a + b ) log add(3, 7) // 10
greet = def() -> ( "Hello" ) log greet() // Hello
calculate = def(x) -> ( squared = x * x squared + 10 ) log calculate(5) // 35