Пример #1
0
// __setattr__: set an item in the maxscript globals hash table
static int
mxs_setattro( PyObject* self, PyObject* key, PyObject* value ) {
	
	//mprintf( _T("mxs_setattro entered\n") );
	MXS_PROTECT( two_value_locals( name, result ) );
	PyStringToMCHAR mkey(key);
	vl.name		= Name::intern( mkey.mchar() );

	// Step 3: get a preexisting global value
	vl.result	= globals->get( vl.name );
	if ( vl.result ) {
		// Step 4: try to set the global variable
		try {
			if ( is_thunk( vl.result ) )
				((Thunk*) vl.result)->assign( ObjectWrapper::intern(value) );
			else
				globals->set( vl.name, ObjectWrapper::intern(value) );
		}
		MXS_CATCHERRORS();
	}

	// Step 5: cleanup the maxscript memory
	MXS_CLEANUP();
	//mprintf( _T("mxs_setattro leaving\n") );
	
	return 0;
}
Пример #2
0
void write(obj_t obj) {
    char c;
    char *str;

    if (obj == imm_empty_list) {
      printf("()");
    } else if (is_pair(obj)) {
      printf("(");
      write_pair(obj);
      printf(")");
    } else if (is_symbol(obj)) {
      printf("%s", unwrap_symbol(obj)->value);
    } else if (is_string(obj)) {
      printf("\"%s\"", unwrap_string(obj)->value);
    } else if (is_boolean(obj)) {
      printf("#%c", obj==imm_false ? 'f' : 't');
    } else if (is_fixnum(obj)) {
      printf("%lld", unwrap_fixnum(obj));
    } else if (is_thunk(obj)) {
      printf("#<thunk>");
    } else if (is_primitive_proc(obj)) { 
      printf("#<primitive fn>");
    } else if (obj == imm_undefined) {
      printf("#<undefined>");
    } else {
      assert(0);
    }
#if 0
        case SYMBOL:
            printf("%s", obj->data.symbol->value);
            break;
        case FIXNUM:
            printf("%ld", obj->data.fixnum);
            break;
        case CHARACTER:
            c = obj->data.character;
            printf("#\\");
            switch (c) {
                case '\n':
                    printf("newline");
                    break;
                case ' ':
                    printf("space");
                    break;
                default:
                    putchar(c);
            }
            break;
        case STRING:
            str = obj->data.string->value;
            putchar('"');
            while (*str != '\0') {
                switch (*str) {
                    case '\n':
                        printf("\\n");
                        break;
                    case '\\':
                        printf("\\\\");
                        break;
                    case '"':
                        printf("\\\"");
                        break;
                    default:
                        putchar(*str);
                }
                str++;
            }
            putchar('"');
            break;
        case PAIR:
            printf("(");
            write_pair(obj);
            printf(")");
            break;
        case PRIMITIVE_PROC:
        case COMPOUND_PROC:
            printf("#<procedure>");
            break;
        default:
            fprintf(stderr, "cannot write unknown type\n");
            exit(1);
    }