Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mraheel

macrumors regular
Original poster
Apr 18, 2009
136
0
Hi guys,

Im kinda new to Mac programming and Obj C. I need to actually port a program from Win to Mac. ( cuz wer supporting mac :) )

I had actually used a pascal library for a custom scripting engine and dynamic controls.

What i mean by this is:

Say, at app run time. I open a txt file. theres simple strings with delimitors and some "script"

The app upon reading adds an Interface Button a List view etc. and Upon clicking the button, it executes a predermined function but with a variable in the script.

example of script from Windows, it could be anything

//these are buttons on UI with location on interface. Well, location can be ignored.
@Button(110,22,111,20);
@Button2(111,22,32,12);
//On clicking buttons.

function_click(Button2) {
show_message('btn 2 was clicked');
}


Nothing has to be exact like this above.. i just want to know if some wrapper, engine like this does exist, which i can use for a GUI application.

any suggestions are appreciated.
 
If you haven't already, look into ANTLR and flex & bison. Both of these are parser generators, and both are cross platform. Flex & bison have been around for a really long time and are therefore stable. ANTLR is relatively new, so it has some kinks to be worked out here and there, but it's a LOT easier to work with. The language EBNF format used by ANTLR is more flexible, and ANTLRWorks actually helps you debug stuff. ANTLR is java, and as such, java is the primary language supported for the parsers it generates, though the C functionality is not far behind. On the other hand, flex & bison both default to producing parsers written in C.

At least at the lexer stage, both are pretty much straight-up regular expressions, so if you are familiar with regex, you'll have an easier time getting started. I like to describe ANTLR as regular expressions on steroids, as the syntax of regular expressions is extended into the parser language, whereas bison has a much simpler/much more limited method of defining parsers.

I could go on and on. I spent several months creating a language in ANTLR earlier this year, and now I'm working on learning flex and bison. The fundamental difference between the two is that ANTLR creates right-to-left parsers with unlimited lookahead, and bison creates left-to-right parsers with single-token lookahead. Each has its strengths and weaknesses, so I can't simply say that one is better than the other. I enjoyed working in ANTLR, but I'm learning bison & flex because I couldn't get a different language to work with ANTLR disallowing left-recursion.
 
There are two approaches I can think of for this:
1) programatically create controls. You can google for this and find some information on this. The short and long is that interface builder generates files that are just serialized objects. You can make these objects, too, it's just going to be harder. Parsing the file shouldn't be too hard.

2) write something that converts your config to .xib files. I don't know where the XML schema for xibs is published, if it is, but since it's XML you should be able to work it out and write your controls to a xib, then load the xib.

I have never done either of these, but I know the first is doable, there have been examples here in the past. The second should be doable, but if the schema isn't public it may be hard.

Another option would be to just have N preset layouts, generate N nibs, then determine which to load at runtime. A new layout would require a new nib/xib. This shouldn't be that much worse than publishing a new config file.

-Lee
 
HTML? JavaScript? Python? TCL? JavaFX?

Any number of languages and GUI toolkits could be used to build this. It depends on exactly what kind of GUI elements need to be presented, and what kind of actions (functions) need to be performed. And it depends on whether you need to preserve any of your existing scripts, layouts, functions, etc.

It also depends a lot on exactly what this GUI scripting language must look like, and whether the GUI elements actually have to be defined as scripted text. For example, it might be more appropriate to create some GUI elements as Interface Builder nib or xib files, and connect them to AppleScript, Python, or other actions.
 
thanks for the suggestions guys.
From my initial thoughts on mac is that all controls are kinda "linked" in the Interface Builder.

What I'd thought of doing was create a subclass for parsing files with control data and XML was kinda obvious choice. I'll make a sinlge empty xib file and utilise it for all "dynamic" views that are generated at runtime.

Its possible to get create controls from a simple xml file. But its the work after that im worried about. The View Conrollers and the Links.


The xibs are XML. but they cant be compiled at runtime? i mean dynamically?

Detrius, thanks for the references you gave, I'll check them out.
 
Its possible to get create controls from a simple xml file. But its the work after that im worried about. The View Conrollers and the Links.

There is nothing that Interface Builder does that cannot be done in code. It may be quite a bit of work, but it can all be done.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.