| 522 | } |
| 523 | |
| 524 | function cwrap (ident, returnType, argTypes) { |
| 525 | argTypes = argTypes || []; |
| 526 | var cfunc = getCFunc(ident); |
| 527 | // When the function takes numbers and returns a number, we can just return |
| 528 | // the original function |
| 529 | var numericArgs = argTypes.every(function(type){ return type === 'number'}); |
| 530 | var numericRet = returnType !== 'string'; |
| 531 | if (numericRet && numericArgs) { |
| 532 | return cfunc; |
| 533 | } |
| 534 | return function() { |
| 535 | return ccall(ident, returnType, argTypes, arguments); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | |
| 540 | Module["cwrap"] = cwrap; |