Changeset 55 for NEWT0/trunk/contrib/NativeCalls/NativeCalls.c
- Timestamp:
- 05/26/06 19:14:30 (3 years ago)
- Files:
-
- 1 modified
-
NEWT0/trunk/contrib/NativeCalls/NativeCalls.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
NEWT0/trunk/contrib/NativeCalls/NativeCalls.c
r31 r55 495 495 theResult = false; 496 496 } 497 } else if (NewtSymbolEqual(inNSType, NSSYM(string))) { 497 } else if ((NewtSymbolEqual(inNSType, NSSYM(string))) 498 || (NewtSymbolEqual(inNSType, NSSYM(iostring)))) { 498 499 *outFFIType = &ffi_type_pointer; 499 500 if (NewtRefIsString(inNSValue)) … … 505 506 theResult = false; 506 507 } 507 } else if (NewtSymbolEqual(inNSType, NSSYM(binary))) { 508 } else if ((NewtSymbolEqual(inNSType, NSSYM(binary))) 509 || (NewtSymbolEqual(inNSType, NSSYM(iobinary)))) { 508 510 *outFFIType = &ffi_type_pointer; 509 511 if (NewtRefIsBinary(inNSValue)) … … 512 514 (void*) NewtRefToBinary(inNSValue); 513 515 } else { 514 (void) NewtThrow(kNErrNotA String, inNSValue);516 (void) NewtThrow(kNErrNotABinaryObject, inNSValue); 515 517 theResult = false; 516 518 } … … 736 738 737 739 /** 738 * Native function lib: DefineGlobalFn(specs)740 * Native function lib:GetFunction(specs) 739 741 * 740 742 * specs is a frame defining the native function. It includes the following … … 742 744 * 743 745 * name (string) name of the native function to call 744 * symbol (symbol) optional name of the global function to define. If not745 * present (or nil), the global function will have the same name as746 * the native function. Use this when names conflicts (e.g. strlen747 * and StrLen)748 746 * args (array of symbols) types of the arguments. 749 747 * result (symbol) type of the result. … … 767 765 * 'longdouble real ffi_type_longdouble 768 766 * 'string string ffi_type_pointer 767 * 'iostring string ffi_type_pointer not available for result 769 768 * 'binary binary ffi_type_pointer not available for result 769 * 'iobinary binary ffi_type_pointer not available for result 770 770 * 'pointer int or binary ffi_type_pointer 771 771 * 772 772 * Structures aren't supported yet. 773 * 774 * The symbol of the function is added to a list of the library object to allow 775 * Close to undefine the function. 773 * string and iostring are identical (strings are I/O). Same with binary and 774 * iobinary. This may change in the future. 776 775 * 777 776 * @param inRcvr self … … 780 779 */ 781 780 newtRef 782 DefineGlobalFn(781 GetFunction( 783 782 newtRefArg inRcvr, 784 783 newtRefArg inSpec) … … 787 786 newtRefVar resultType; 788 787 newtRefVar functionName; 789 newtRefVar functionSymbol;790 788 newtRefVar functionObject; 791 newtRefVar libList;792 789 793 790 /* check self */ … … 820 817 { 821 818 return NewtThrow(kNErrNotAString, functionName); 822 }823 functionSymbol = NcGetSlot(inSpec, NSSYM(symbol));824 if (NewtRefIsNIL(functionSymbol))825 {826 functionSymbol = NewtMakeSymbol(NewtRefToString(functionName));827 } else if (!NewtRefIsSymbol(functionSymbol)) {828 return NewtThrow(kNErrNotASymbol, functionSymbol);829 }830 831 /* check the function doesn't exist yet */832 if (NewtHasGlobalFn(functionSymbol))833 {834 return NewtThrow(835 kNErrNative,836 NewtMakeString("Global function already exists", true));837 819 } 838 820 … … 847 829 NcSetSlot(functionObject, NSSYM(_argTypes), argTypes); 848 830 831 return functionObject; 832 } 833 834 /** 835 * Native function lib:DefGlobalFn(symbol, specs) 836 * 837 * symbol is the symbol of the function to define. 838 * specs is a frame defining the native function. It is passed to GetFunction. 839 * 840 * The symbol of the function is added to a list of the library object to allow 841 * Close to undefine the function. 842 * 843 * @param inRcvr self 844 * @param inSymbol function symbol 845 * @param inSpec specification frame 846 * @return NIL 847 */ 848 newtRef 849 DefGlobalFn( 850 newtRefArg inRcvr, 851 newtRefArg inSymbol, 852 newtRefArg inSpec) 853 { 854 newtRefVar functionObject; 855 newtRefVar libList; 856 857 /* check the function doesn't exist yet */ 858 if (NewtHasGlobalFn(inSymbol)) 859 { 860 return NewtThrow( 861 kNErrNative, 862 NewtMakeString("Global function already exists", true)); 863 } 864 865 /* Get the object */ 866 functionObject = GetFunction(inRcvr, inSpec); 867 849 868 /* add the function to the list */ 850 869 libList = NcGetSlot(inRcvr, NSSYM(_globalFns)); … … 854 873 NcSetSlot(inRcvr, NSSYM(_globalFns), libList); 855 874 } 856 NcAddArraySlot(libList, functionSymbol);875 NcAddArraySlot(libList, inSymbol); 857 876 858 877 /* define the global function */ 859 NcDefGlobalFn( functionSymbol, functionObject);860 861 return kNewtRefNIL;878 NcDefGlobalFn(inSymbol, functionObject); 879 880 return inSymbol; 862 881 } 863 882 … … 959 978 Close, 0, "Close()")); 960 979 NcSetSlot(magicPtr, 961 NSSYM( DefineGlobalFn),980 NSSYM(GetFunction), 962 981 NewtMakeNativeFunc( 963 DefineGlobalFn, 1, "DefineGlobalFn(specs)")); 982 GetFunction, 1, "GetFunction(spec)")); 983 NcSetSlot(magicPtr, 984 NSSYM(DefGlobalFn), 985 NewtMakeNativeFunc( 986 DefGlobalFn, 2, "DefGlobalFn(symbol, spec)")); 964 987 965 988 NcDefMagicPointer(kLibParentMagicPtrKey, magicPtr);
