AH, I was talking to fponticelli and he said something and it struck me what
I am doing wrong here.
This is the right c++ code :
void ncb_quickLoad(value module)
{
value o = val_field(module,val_id("NekoPtkGame"));
if( val_is_object(o))
{
value f = val_field(o,val_id("cb_quickLoad"));
if( val_is_function(f))
{
val_call0(f);
}
}
}
Now I can call functions within object that I created in neko language to
mimic what Danny said and it works.
I will go now further where I already noticed new problem, but I have to dig
deeper about it now that this works and see if I can solve it without asking
here. (When I compiled the minimal haxe file with haxe to .n my c++ app just
exits).
I already have material for 2 short tutorials until now. One is how to call
back into c++ app from embeded neko, ano another short one is this with
objects.
Best regards,
Janko
On Fri, Oct 10, 2008 at 8:28 PM, janko metelko <[EMAIL PROTECTED]> wrote:
> Thanks for your reply Danny, you cleared a lot of things to me.
>
> How does this change the c++ code in the example?
>
> ------------
> void execute( value module ) {
> value x = val_field(module,val_id("x"));
>
> --------
>
> I tried the . : :: => between object name nad variable and nothing of these
> seemed to work.
>
> ------------
> void execute( value module ) {
> value x = val_field(module,val_id("Main.x")); // this didn't work
>
> --------
>
> This is my code otherwise. I tried to make it first work with object in
> pure neko as the n that I compiled from haxe exited my app, so I figure if I
> manage to make it work with neko with exported variables inside object first
> ... then I can start solving the the other thing.
>
> --- NEKO CODE WITH OBJECT ---
>
> var x = 0;
> var dir = 1;
>
> $exports.NekoPtkGame = {
> cb_quickLoad => function() {
> var load = $loader.loadprim("loadImg", 1);
> load("img\\bg\\golf_s.jpg");
> load("img\\spr\\tank1.png");
> },
>
> cb_update => function() {
> var draw = $loader.loadprim("drawImg", 5);
> draw(800, 600, 0, 0, 0);
> draw(105, 95, x, 500, 1);
> x = 3 * dir + x;
> if ( x < 0 ) dir = 1;
> if ( x > 700 ) dir = -1;
> }
> }
>
> --- C ++ CODE NOW :
>
> void ncb_quickLoad(value module)
> {
> value f = val_field(module,val_id("NekoPtkGame.cb_quickLoad"));
> if( !val_is_function(f) ) return;
> val_call0(f);
> }
>
> void ncb_update(value module)
> {
> value f = val_field(module,val_id("NekoPtkGame.cb_update"));
> if( !val_is_function(f) ) return;
> val_call0(f);
> }
>
> -----
>
> val_is_function() returned false in both times (now when I added object,
> witout it directly it works)
>
> Best regards, Thanks so far!
>
> Janko
>
>
> I tried the object.
>
> Op Thu, 09 Oct 2008 23:08:46 +0200 schreef janko metelko <
>> [EMAIL PROTECTED]>:
>>
>> $exports.x = 33;
>>> $exports.f = function(x) { return x * 2 + 1; }
>>>
>>> This is all no problem to me, C and neko side works and all. But can you
>>> Nicolas or anybody else please show me what would the Haxe version of this
>>> small example be. A Haxe code that after compiled to .n exports some value x
>>> and some function f that calculates something. If such thing is possible?
>>>
>>
>> haXe requires variables to be in classes, so the closest would be:
>>
>> // ------------
>> // haXe
>> class Main {
>> static var x = 33;
>> }
>>
>> // ------------
>>
>> // Neko output
>> $exports.Main.x = 33;
>> // ------------
>>
>>
>> Every haXe class is an object in Neko. So all statics are accessible in
>> the exports.
>>
>> That's why Nicolas wrote:
>>
>> Op Thu, 09 Oct 2008 09:59:58 +0200 schreef Nicolas Cannasse <
>> [EMAIL PROTECTED]>:
>>
>> $exports.my.package.MyClass
>>> (or the equivalent by using Neko API)
>>> You can create an instance by calling MyClass.new(p1,p2,...) and the
>>> call the methods etc.
>>>
>>
>>
>> Kind regards,
>>
>> Danny Wilson
>>
>> deCube - design and development
>>
>> Mobile [ 06 - 5232 1813
>> e-Mail [ [EMAIL PROTECTED]
>> web URL [ http://www.decube.net/
>>
>>
>> --
>> Neko : One VM to run them all
>> (http://nekovm.org)
>>
>
>
--
Neko : One VM to run them all
(http://nekovm.org)