[gambit-list] Problem with interactive development using remote REPL of iOS Sim.

Tatsuya Tsuda otabat at gmail.com
Wed Feb 27 04:03:17 EST 2013


Hi, I am a newbie of Gambit Scheme coming from Clojure.
Currently I am trying to build an iOS app in Gambit.
I have successfully done the following:
1. Built 4.6.6-devel git version (snapshot of two weeks ago) of Gambit
using llvm-gcc
2. Built Gambit REPL using iOS SDK 6.1 by using both clang and llvm-gcc
from Xcode.
3. Minimized the remote REPL part of Gambit REPL and created a simple app
3.1. Created a scheme file, init.scm, to register and change the text of
the UILabel.

;; The whole init.scm
(declare (standard-bindings)
         (extended-bindings)
         (block)
         (fixnum)
         ;(not safe)
         )

(c-define-type UILabel* (pointer "UILabel"))

(c-declare "#import <UIKit/UIKit.h>")
(define current-label #f)

(c-define (register-label label) (UILabel*) void "register_label" ""
          (set! current-label label))

(define change-label-text
  (c-lambda ((pointer "UILabel")) void #<<c-code
            ___arg1.text = @"Text changed.";
c-code
))

3.2. In Xcode, I defined a viewDidLoad method as below, which prints "Hello
Wolrd" and then passes the label to the scheme function register_label().

// Part of VIewController.m
- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

    _label = [[UILabel alloc] init];
    _label.text = @"Hello World";
    [_label setLineBreakMode:UILineBreakModeWordWrap];
    [_label setNumberOfLines:0];
    _label.frame = CGRectMake(0, 225, 320, 30);
    _label.textAlignment = UITextAlignmentCenter;
    [self.view addSubview:_label];

    _timer = nil;
    _queuedActions = [[NSMutableArray alloc] init];

    gambit_setup();
    register_label(_label);
    repl_server_start();
    [self heartbeat_tick];
}

So far, I have successfully built this simple app. I can connect to the
remote REPL of iOS Simulator from the Emacs Inferior Lisp, and even able to
change the text of the label dynamically by doing like (change-label-text
current-label).

Now it seems that I can develop iOS apps, but I want to go further with the
interactive development using the REPL.
What I want to do is like:
1. Redefine the change-label-text function by changing the text like "New
text!"

2. Create a loadable library
gsc -cc-options "-arch i386 -x objective-c -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk
-D__IPHONE_OS_VERSION_MIN_REQUIRED=40300" -ld-options "-framework
CoreFoundation -framework Foundation -framework UIKit" lib/init.scm

3. Do below in REPL
(define old-label current-label)

4. Load the loadable library init.o1 from the REPL

5. Do below in REPL
(change-label-text old-label)

6. Then an error in Xcode and the app terminates.
2013-02-27 17:38:31.305 gambit-test[61410:11303] *** NSForwarding: warning:
selector (0x87a6f44) for message 'setText:' does not match selector known
to Objective C runtime (0xabb96d)-- abort
2013-02-27 17:38:31.306 gambit-test[61410:11303] -[UILabel setText:]:
unrecognized selector sent to instance 0x8284a50
2013-02-27 17:38:31.306 gambit-test[61410:11303] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel
setText:]: unrecognized selector sent to instance 0x8284a50'
*** First throw call stack:
(0x21a4012 0x15e1e7e 0x222f4bd 0x2193bbc 0x219394e 0x87a6e07 0x44b0c0)
libc++abi.dylib: terminate called throwing an exception


I can  create and load a loadable library with no errors. It seems that
something is missing.
Does anyone know how to solve this kind of problem?

Thanks,
Tatsuya Tsuda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20130227/34971981/attachment.htm>


More information about the Gambit-list mailing list