Event handlers in a different module than form definition?
Posted: Tue Sep 09, 2008 7:22 am
I am a newcomer to newlisp and am not sure how to break my code up in modules when it comes to gui forms.
The app I'd like to write will need a few forms and I would like to save each form definition (hence calls to gs: functions) in its own file. Actions local to each form would be defined within that form's file. Other actions would ideally be defined as passing control to some controller defined in the main file.
I tried the code below, but it fails and reports the following error:
My code goes like this:
Form1 file goes like this:
Thanks in advance,
Alex
The app I'd like to write will need a few forms and I would like to save each form definition (hence calls to gs: functions) in its own file. Actions local to each form would be defined within that form's file. Other actions would ideally be defined as passing control to some controller defined in the main file.
I tried the code below, but it fails and reports the following error:
Code: Select all
ERR: symbol is protected in function setq : callback
called from user defined function form1
called from user defined function app:run
Code: Select all
#!/usr/bin/env newlisp
; app.lsp
;
;; load modules
(load (append (env "NEWLISPDIR") "/guiserver.lsp"))
(load "form1.lsp")
(load "form2.lsp")
;; definitions
(context 'app)
;;; handlers
(define (app:got-event id value)
(begin
()))
;;; run
(define (run)
(begin
(setq f1 (form1 'app:got-event))
(setq f2 (form2 'app:got-event))
(gs:set-visible 'f1 true)
(gs:listen)))
;; go
(run)
Code: Select all
#!/usr/bin/env newlisp
; form1.lsp
;
;; load modules
(load (append (env "NEWLISPDIR") "/guiserver.lsp"))
;; definitions
(context 'form1)
(define (form1:form1 callback)
(begin
(gs:init)
(gs:frame 'Form1 200 200 320 480 "Form 1")
(gs:button 'Btn1 callback "OK 1")
(gs:add-to 'Form1 'Btn1)))
Alex