Re: load user defined module
- Posted by Derek Parnell <ddparnell at bigpond.com> Nov 08, 2002
- 398 views
Robert, is this the sort of thing you are suggesting for us ? ... include linux/ui.e as lui include win32/ui.e as wui include dos/ui.e as dui . . . function CreateWidget( object WidgetType, object Caption, ... ) object lResult if platform() = UNIX then lResult = lui:CreateWidget(WidgetType, Caption, ...) elsif platform() = WIN32 then lResult = wui:CreateWidget(WidgetType, Caption, ...) elsif platform() = MSDOS then lResult = dui:CreateWidget(WidgetType, Caption, ...) end if return lResult end function procedure PositionCaret( object Widget, object Left, object Top) if platform() = UNIX then lui:PositionCaret(Widget, Left, Top) elsif platform() = WIN32 then wui:PositionCaret(Widget, Left, Top) elsif platform() = MSDOS then dui:PositionCaret(Widget, Left, Top) end if end procedure procedure RenderText( object Widget, object Text) if platform() = UNIX then lui:RenderText(Widget, Text) elsif platform() = WIN32 then wui:RenderText(Widget, Text) elsif platform() = MSDOS then dui:RenderText(Widget, Text) end if end procedure procedure ProcessMessages( object Widget) if platform() = UNIX then lui:ProcessMessages( Widget ) elsif platform() = WIN32 then wui:ProcessMessages( Widget ) elsif platform() = MSDOS then dui:ProcessMessages( Widget ) end if end procedure object Window, Button, . . . if platform() = UNIX then Window = lui:Window Button = lui:Button . . . elsif platform() = WIN32 then Window = wui:Window Button = wui:Button . . . elsif platform() = MSDOS then Window = dui:Window Button = dui:Button . . . end if constant MainWindow = CreateWidget( Window, "My Window", ...), OkayBtn = CreateWidget( Button, "Okay", ...) PositionCaret(MainWindow, 20, 20) RenderText(MainWindow, "Hello, World!") ProcessMessages(MainWindow) ---------------- As you could imagine, it would not take much for this to become very hard to maintain. Can you suggest a better approach? Maybe something along the lines of ... if platform() = UNIX then include linux/ui.e if platform() = WIN32 then include win32/ui.e if platform() = MSDOS then include dos/ui.e end if constant MainWindow = CreateWidget( Window, "My Window", ...), OkayBtn = CreateWidget( Button, "Okay", ...) PositionCaret(MainWindow, 20, 20) RenderText(MainWindow, "Hello, World!") ProcessMessages(MainWindow) -------------- cheers, Derek Parnell ----- Original Message ----- From: "Robert Craig" <rds at RapidEuphoria.com> To: "EUforum" <EUforum at topica.com> Sent: Friday, November 08, 2002 3:46 PM Subject: Re: load user defined module > > Derek Parnell writes: > > Rob, how would you recommend that coders deal with > > this issue of platform-specific code, using the > > current incarnation of Euphoria? > > You can use platform() to determine which platform > you are running on. platform() is fast. It's as if you had > coded a constant, like 1, 2 or 3. No subroutine call is made. > > Euphoria does not have conditional compilation built into it, > like C does. I'd like to keep it that way. Why add > a new concept to the language, for such a small advantage? > > With conditional compilation, or a preprocessor of some kind, > you could eliminate code that's only used on another platform, > thereby saving a few K bytes. > > However it's extremely rare, and getting rarer each year, for > a program to run out of memory because it contains > too much code. It's almost always an excess amount of data that > causes the problem. Over time, programs grow linearly (at most) > in size, while memory is still growing exponentially, > so I expect this to be even less of a problem in the future. > > If you really want to save a few K by stripping out code, > you can develop your own simple preprocessor in > an hour or so. > > I know from coding in C, that it's more readable if all > your nested conditional statements are at the same linguistic level, > using if-else, rather than having two levels, with static ifdef's > and dynamic if's mixed together. > > Something I could do is optimize statements like: > if platform()=LINUX then > code-block-1 > else > code-block-2 > end if > so that no intermediate code is generated for code-block-2 > when the platform is LINUX. I'd rather do that, than introduce > conditional compilation. > > Also the code above, when translated with E to C, > will produce C code like: > > if 3 = 3 then > code-block-1 > else > code-block-2 > end if > > where I know that Watcom (at least) will eliminate > code-block-2 at compile-time. > > Keep in mind also, that the 2-pass binder and the translator > will eliminate all unused routines. > > Regards, > Rob Craig > Rapid Deployment Software > http://www.RapidEuphoria.com > > > >