home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / DevTools / COWS / Code / COWSExampleLibrary.m < prev    next >
Encoding:
Text File  |  1994-03-25  |  7.1 KB  |  417 lines

  1. /*
  2.     Copyright (C) 1994 Sean Luke
  3.  
  4.     COWSExampleLibrary.m
  5.     Version 1.0
  6.     Sean Luke
  7.     
  8. */
  9.  
  10.  
  11.  
  12.  
  13. #import "COWSExampleLibrary.h"
  14.  
  15. @implementation COWSExampleLibrary
  16.  
  17. - loadLibrary:sender
  18.     {
  19.     id returnval=[super loadLibrary:sender];
  20.     
  21.     if (![sender conformsTo:@protocol(LibraryControl)])
  22.         {
  23.         printf ("StandardLibrary error:  Interpreter cannot accept Library Control protocol!\n");
  24.         return NULL;
  25.         }
  26.         
  27.         [sender addLibraryFunction:"scroll-value"
  28.             selector:@selector(scrollValue:)
  29.             target:self];
  30.     
  31.         [sender addLibraryFunction:"set-scroll-value"
  32.             selector:@selector(setScrollValue:)
  33.             target:self];
  34.     
  35.         [sender addLibraryFunction:"check-value"
  36.             selector:@selector(checkValue:)
  37.             target:self];
  38.     
  39.         [sender addLibraryFunction:"set-check-value"
  40.             selector:@selector(setCheckValue:)
  41.             target:self];
  42.     
  43.         [sender addLibraryFunction:"radio-value"
  44.             selector:@selector(radioValue:)
  45.             target:self];
  46.     
  47.         [sender addLibraryFunction:"select-radio-value"
  48.             selector:@selector(setRadioValue:)
  49.             target:self];
  50.     
  51.         [sender addLibraryFunction:"press-button"
  52.             selector:@selector(pressButton:)
  53.             target:self];
  54.     
  55.         [sender addLibraryFunction:"set-string-value"
  56.             selector:@selector(setStringValue:)
  57.             target:self];
  58.     
  59.         [sender addLibraryFunction:"string-value"
  60.             selector:@selector(stringValue:)
  61.             target:self];
  62.     
  63.         [sender addLibraryFunction:"set-window-position"
  64.             selector:@selector(setWindowPosition:)
  65.             target:self];
  66.     
  67.         [sender addLibraryFunction:"window-x-position"
  68.             selector:@selector(windowXPosition:)
  69.             target:self];
  70.     
  71.         [sender addLibraryFunction:"window-y-position"
  72.             selector:@selector(windowYPosition:)
  73.             target:self];
  74.     
  75.         [sender addLibraryFunction:"window-title"
  76.             selector:@selector(windowTitle:)
  77.             target:self];
  78.     
  79.         [sender addLibraryFunction:"set-window-title"
  80.             selector:@selector(setWindowTitle:)
  81.             target:self];
  82.             
  83.         [sender addLibraryFunction:"ping"
  84.             selector:@selector(ping:)
  85.             target:self];
  86.             
  87.     return returnval;
  88.     }
  89.     
  90.     
  91. - scrollValue:arg_list
  92.     {
  93.     id returnval=[[COWSStringNode alloc] init];
  94.     id item;
  95.     char buf[COWSLARGENUMBER];
  96.     
  97.     if ([arg_list top]==NULL)                 // no args
  98.         {
  99.         [returnval setString:"f"];
  100.         return returnval;
  101.         }
  102.     
  103.     item=[arg_list pop];
  104.     
  105.     sprintf(buf,"%f",
  106.         [[scroll cellAt:0:(int)atof([item string])] floatValue]);
  107.     [item free];
  108.     
  109.     [returnval setString:buf];
  110.     return returnval;
  111.     }
  112.     
  113.     
  114. - setScrollValue:arg_list
  115.     {
  116.     id returnval=[[COWSStringNode alloc] init];
  117.     id item,value;
  118.     
  119.     if ([arg_list top]==NULL)                 // no args
  120.         {
  121.         [returnval setString:"f"];
  122.         return returnval;
  123.         }
  124.     
  125.     item=[arg_list pop];
  126.     
  127.     if ([arg_list top]==NULL)                 // just one arg
  128.         {
  129.         [returnval setString:"f"];
  130.         [item free];
  131.         return returnval;
  132.         }
  133.  
  134.     value=[arg_list pop]; 
  135.     
  136.     [[scroll cellAt:0:(int)atof([item string])] 
  137.         setFloatValue:atof([value string])];
  138.     [item free];
  139.     [value free];
  140.     
  141.     [returnval setString:"t"];
  142.     return returnval;
  143.     }
  144.     
  145.  
  146. - checkValue:arg_list
  147.     {
  148.     id returnval=[[COWSStringNode alloc] init];
  149.     id item;
  150.     BOOL x;
  151.     
  152.     if ([arg_list top]==NULL)                 // no args
  153.         {
  154.         [returnval setString:"f"];
  155.         return returnval;
  156.         }
  157.     
  158.     item=[arg_list pop];
  159.     
  160.     x=(BOOL)[[check cellAt:(int)atof([item string]):0] state];
  161.     [item free];
  162.     
  163.     [returnval setString:(x ? "t" : "f")];
  164.     return returnval;
  165.     }
  166.     
  167.  
  168. - setCheckValue:arg_list
  169.     {
  170.     id returnval=[[COWSStringNode alloc] init];
  171.     id item,value;
  172.     
  173.     if ([arg_list top]==NULL)                 // no args
  174.         {
  175.         [returnval setString:"f"];
  176.         return returnval;
  177.         }
  178.     
  179.     item=[arg_list pop];
  180.     
  181.     if ([arg_list top]==NULL)                 // just one arg
  182.         {
  183.         [returnval setString:"f"];
  184.         [item free];
  185.         return returnval;
  186.         }
  187.  
  188.     value=[arg_list pop]; 
  189.     
  190.     [[check cellAt:(int)atof([item string]):0] 
  191.         setIntValue:!strcmp([value string],"t") ? 1 : 0];
  192.     [item free];
  193.     [value free];
  194.     
  195.     [returnval setString:"t"];
  196.     return returnval;
  197.     }
  198.     
  199.  
  200. - radioValue:arg_list
  201.     {
  202.     id returnval=[[COWSStringNode alloc] init];
  203.     id item;
  204.     BOOL x;
  205.     
  206.     if ([arg_list top]==NULL)                 // no args
  207.         {
  208.         [returnval setString:"f"];
  209.         return returnval;
  210.         }
  211.     
  212.     item=[arg_list pop];
  213.     
  214.     x=(BOOL)[[radio cellAt:(int)atof([item string]):0] floatValue];
  215.     [item free];
  216.     
  217.     [returnval setString:(x ? "t" : "f")];
  218.     return returnval;
  219.     }
  220.     
  221.  
  222. - setRadioValue:arg_list
  223.     {
  224.     id returnval=[[COWSStringNode alloc] init];
  225.     id item;
  226.     
  227.     if ([arg_list top]==NULL)                 // no args
  228.         {
  229.         [returnval setString:"f"];
  230.         return returnval;
  231.         }
  232.     
  233.     item=[arg_list pop];
  234.     
  235.     [radio selectCellAt:(int)atof([item string]):0];
  236.     [item free];
  237.     
  238.     [returnval setString:"t"];
  239.     return returnval;
  240.     }
  241.     
  242.  
  243. - pressButton:arg_list
  244.     {
  245.     id returnval=[[COWSStringNode alloc] init];
  246.     id item;
  247.     
  248.     if ([arg_list top]==NULL)                 // no args
  249.         {
  250.         [returnval setString:"f"];
  251.         return returnval;
  252.         }
  253.     
  254.     item=[arg_list pop];
  255.     
  256.     [[button cellAt:(int)atof([item string]):0] performClick:self];
  257.     [item free];
  258.     
  259.     [returnval setString:"t"];
  260.     return returnval;
  261.     }
  262.     
  263.  
  264. - setStringValue:arg_list
  265.     {
  266.     id returnval=[[COWSStringNode alloc] init];
  267.     id item,value;
  268.     
  269.     if ([arg_list top]==NULL)                 // no args
  270.         {
  271.         [returnval setString:"f"];
  272.         return returnval;
  273.         }
  274.     
  275.     item=[arg_list pop];
  276.     
  277.     if ([arg_list top]==NULL)                 // just one arg
  278.         {
  279.         [returnval setString:"f"];
  280.         [item free];
  281.         return returnval;
  282.         }
  283.  
  284.     value=[arg_list pop]; 
  285.     
  286.     [[field cellAt:(int)atof([item string]):0] 
  287.         setStringValue:[value string]];
  288.     [item free];
  289.     [value free];
  290.     
  291.     [returnval setString:"t"];
  292.     return returnval;
  293.     }
  294.     
  295.  
  296. - stringValue:arg_list
  297.     {
  298.     id returnval=[[COWSStringNode alloc] init];
  299.     id item;
  300.     
  301.     if ([arg_list top]==NULL)                 // no args
  302.         {
  303.         [returnval setString:"f"];
  304.         return returnval;
  305.         }
  306.     
  307.     item=[arg_list pop];
  308.     
  309.     [returnval setString:
  310.         [[field cellAt:(int)atof([item string]):0] stringValue]];
  311.     [item free];
  312.     
  313.     return returnval;
  314.     }
  315.     
  316.  
  317. - setWindowPosition:arg_list
  318.     {
  319.     id returnval=[[COWSStringNode alloc] init];
  320.     id item,value;
  321.     
  322.     if ([arg_list top]==NULL)                 // no args
  323.         {
  324.         [returnval setString:"f"];
  325.         return returnval;
  326.         }
  327.     
  328.     item=[arg_list pop];
  329.     
  330.     if ([arg_list top]==NULL)                 // just one arg
  331.         {
  332.         [returnval setString:"f"];
  333.         [item free];
  334.         return returnval;
  335.         }
  336.  
  337.     value=[arg_list pop]; 
  338.     
  339.     [window moveTo:atof([item string]):atof([value string])];
  340.     [item free];
  341.     [value free];
  342.     
  343.     [returnval setString:"t"];
  344.     return returnval;
  345.     }
  346.     
  347.  
  348. - windowXPosition:arg_list
  349.     {
  350.     id returnval=[[COWSStringNode alloc] init];
  351.     char buf[COWSLARGENUMBER];
  352.     NXRect rect;
  353.     
  354.     [window getFrame:&rect];
  355.     sprintf(buf,"%f",rect.origin.x);
  356.     [returnval setString:buf];
  357.     return returnval;
  358.     }
  359.     
  360.  
  361. - windowYPosition:arg_list
  362.     {
  363.     id returnval=[[COWSStringNode alloc] init];
  364.     char buf[COWSLARGENUMBER];
  365.     NXRect rect;
  366.     
  367.     [window getFrame:&rect];
  368.     sprintf(buf,"%f",rect.origin.y);
  369.     [returnval setString:buf];
  370.     return returnval;
  371.     }
  372.     
  373.  
  374. - windowTitle:arg_list
  375.     {
  376.     id returnval=[[COWSStringNode alloc] init];
  377.     
  378.     [returnval setString:[window title]];
  379.     return returnval;
  380.     }
  381.     
  382.  
  383. - setWindowTitle:arg_list
  384.     {
  385.     id returnval=[[COWSStringNode alloc] init];
  386.     id item;
  387.     
  388.     if ([arg_list top]==NULL)                 // no args
  389.         {
  390.         [returnval setString:"f"];
  391.         return returnval;
  392.         }
  393.     
  394.     item=[arg_list pop];
  395.     
  396.     [window setTitle:[item string]];
  397.     [item free];
  398.     
  399.     [returnval setString:"t"];
  400.     return returnval;
  401.     }
  402.  
  403. - ping:arg_list
  404.     {
  405.     id returnval=[[COWSStringNode alloc] init];
  406.     NXPing();
  407.     [returnval setString:"t"];
  408.     return returnval;
  409.     }
  410.  
  411. - pauseCancelled:sender
  412.     {
  413.     return self;
  414.     }
  415.  
  416.         
  417. @end