> I am trying to do this:
>
> C++ LUA
>
> text inserted in InputBox
> enter key pressed
> luaL_doString(givenString) =>
> receive string
> interpretate string
> oh, it's a shader!
> call c function and pass
> the specified parameter
> eg mapping string
> to number
> <=
> shader set
> scene updated
>
> This is how the C++ function is defined:
>
> int setShader(lua_State *L)
> {
> int type=lua_tonumber(L,1);
> shaders.current=type;
> return 1;
> }
>
If I've understood this would traduce to:
[Smalltalk]
Smalltalk cCall: 'setShader' withArguments: #(1)
[C side]
SYX_FUNC_PRIMITIVE(setShader)
{
SYX_PRIM_ARGS(1); /* ensure there's at least one parameter, it's optional
*/
int type = SYX_SMALL_INTEGER (es->message_arguments[0]);
shaders.current = type;
return 1;
}
[Interpreting the smalltalk code]
SyxOop process = syx_process_new ();
SyxOop string = syx_string_new (CODE_TO_BE_INTERPRETED);
SyxOop context = syx_send_unary_message (string, "doIt");
syx_interp_enter_context (process, context);
syx_process_execute_blocking (process);
As you can see, it's much more verbose.
For the next release I intend to create some helper functions for
interpreting text,
so that you can do something like:
SyxOop process = syx_string_execute_blocking (receiver,
CODE_TO_BE_INTERPRETED);
While for the Smalltalk code, well it's smalltalk :) There're no
functions, only methods.
But you can still do something more clean (IMHO), run the interpreted code
into an object.
You can create such a class:
Object subclass: #Application
instanceVariableNames: ''!
!Application methodsFor: 'primitives'
shader: aValue
<cCall: 'setShader'>
! !
Then you can have a string to interpret like this:
self shader: 1
That's it, yet more verbose. If you like you can also add instance
variables and so on to the object and access them after the interpretation.
No you're not bothering me. Though syx is really young and not as stable
as other languages, I care about quality, so I'm not happy with these
problems.
I'd suggest you to read the GNU smalltalk documentation.
> The lua string is just setShader(1) which is the inserted string on
> the input box.
> So I have several calls of one function with different parameters.
> Is there any documentation in syx to describe the whole thing both
> ways?
> The example calls a Syx function, but I need something more similar to
> an eval() function
> (fundamentally the execution of a block passed as a string).
> Then I seem to understand I need a primitive. Any place I can found
> docs?
> This far I am reading Smalltalk by Example and Squeak by Example to
> learn some smalltalk, if you have other suggestions as sources they'd
> be welcome :)
>
> I hope I am not bothering, just try to see how syx could fit in my
> app. I know you already have plenty of work to do, so in case you find
> it bothering just say it, no offense :P
>
> Greetings and wishes of a good day :)
> D.
--
http://lethalman.blogspot.com - Thoughts about computer technologies
http://code.google.com/p/syx - A new Smalltalk implementation
http://www.ammazzatecitutti.org - E adesso ammazzateci tutti