alchemy中定义多个方法

来源:互联网 发布:iphone用usb共享网络 编辑:程序博客网 时间:2024/06/06 19:57
原文:http://www.cnblogs.com/176170847/archive/2011/01/27/1946206.html
 
//Simple String Echo example//mike chambers //mchamber@adobe.com  #include <stdlib.h>#include <stdio.h>  //Header file for AS3 interop APIs//this is linked in by the compiler (when using flaccon)#include "AS3.h"  doublesum(int num) {      inti;      doubletotal=0;      for(i=1;i<=num;i++)      {         total += i;     }     returntotal; }   //Method exposed to ActionScript//Takes a String and echos itstaticAS3_Val echo(void* self, AS3_Val args){     //9 variable    intnum;     doubletotal;     charbuf[256];       AS3_ArrayValue(args,"IntType", &num);           total = sum(num);    sprintf(buf,"%lf", total);     returnAS3_String(buf); }   //try new functionstaticAS3_Val returnTheSelf(void* self,AS3_Val args){    //initialize string to null    char* val = NULL;          //parse the arguments. Expect 1.    //pass in val to hold the first argument, which    //should be a string    AS3_ArrayValue( args,"StrType", &val );          //if no argument is specified    if(val == NULL)    {        char* nullString ="null";         //return the string "null"        returnAS3_String(nullString);     }          //otherwise, return the string that was passed in    returnAS3_String(val);   }   //entry point for codeint main() {     //define the methods exposed to ActionScript    //typed as an ActionScript Function instance    AS3_Val echoMethod = AS3_Function( NULL, echo );    AS3_Val returnTheSelfMethod=AS3_Function(NULL,returnTheSelf);      // construct an object that holds references to the functions    AS3_Val result = AS3_Object("echo: AS3ValType,returnTheSelf:AS3ValType", echoMethod ,returnTheSelfMethod);    //result=AS3_Object("returnTheSelf:AS3ValType",returnTheSelfMethod);      // Release    AS3_Release( echoMethod );    AS3_Release(returnTheSelfMethod);      // notify that we initialized -- THIS DOES NOT RETURN!    AS3_LibInit( result );      // should never get here!    return0; }

原创粉丝点击