Another silly primitive question

Andrew C. Greenberg werdna at gate.net
Sun Feb 14 01:04:16 UTC 1999


> Hi,
>  
> My next silly primitive plug in question. How do I place a #include 
> statement into my plug-in primitive?
>  
> E.g. I want to say "#include <foo.h>" into my plug in code stream. 
> How do I do this?
>  
> Jim

I didn't see a trivially easy way to do this a while ago, so I did it 
a bit obliquely.

(1) create a subclass of PluggableCodeGenerator (I called it 
PluginCodeGenerator) and redefined:

emitCHeaderOn: aStream
	"Write a C file header onto the given stream."

	super emitCHeaderOn: aStream.
	aStream nextPutAll: '/* Adding Plugin Header Code */'; cr.
	aStream nextPutAll: headerString; cr; cr.

where headerString is an instance variable with all of my include 
stuff.  I redefined:

emitCHeaderForPrimitivesOn: aStream

in a similar manner.

(2) On the class side of your plugin (which should already be a 
subclass of InterpreterPlugin), add the message

	translate: fileName doInlining: inlineFlag

by copying the corresponding code from InterpreterPlugin class, but 
patching it to use PluginCodeGenerator in lieu of 
PluggableCodeGenerator.

I'm sure there's an easier way, but this worked for me, so I just 
stopped thinking.





More information about the Squeak-dev mailing list