Advertisement

Using precompiled byte-code

Started by June 19, 2012 12:46 PM
5 comments, last by WitchLord 12 years, 2 months ago
Hi,

I try use precompiled byte-code. I successfully compile my script then successfully loaded it but I has encountered with serious trouble - i got erorr id trying obtain fucntion id by calling GetGlobalVarIndexByName or GetFunctionIdByDecl. Also functions GetFunctionCount() and GetGlobalVarCount return 0.

Why i done wrong? Maybe there are special condition need when generated byte code?

Best reards,
Eugene.
Did LoadBytecode() return an error?

Did you receive any messages on the message callback?

Can you show how you did it? There is nothing special that needs to be done. Just follow the instructions in the manual.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
Thanks for reply :)

so I just call mod->SaveByteCode(&stream); after i compile script.
Before load byte-code I call machine->SetEngineProperty(asEP_INIT_GLOBAL_VARS_AFTER_BUILD, 0) and then call mod->LoadByteCode(&straem);
LoadByteCode do not return error.

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]I do not use message callback maybe i need check callback for output?[/background]

[/font]

Best regards,
Eugene.

The message callback can give useful hints on errors that occur. However, as you say the LoadByteCode() doesn't return any error, then the message stream would have any information either.

From what you're saying you're not doing anything wrong. The bytecode should be loaded properly and the functions and global variables should be available after the load.

Can you debug into the LoadByteCode() too see what is happening? It looks like you're loading an empty script.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

i add log function to BinaryStream to see if anything happens and yes scriptmodule loading bytecode by small chunks

there is code snapshot:


void ScriptModule::BytecodeStreamLoader::Read(void *ptr, asUINT size)
{
memcpy(ptr, buffer, size);
buffer += size;

//core.Trace("Read bc %i", size);
}

ok, i will try debug [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]LoadByteCode() [/background]

[/font]

Hi!

After debuging angelscript i found my stupid mistake i call build after loading bytecode thats leads to reset script module.

Also i found another my mistake i call [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]machine->SetEngineProperty(asEP_INIT_GLOBAL_VARS_AFTER_BUILD, 0) before loading byte code. This leads to broke script.[/background]

[/font]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]So i remove unnesessery calls and all work like charm on all 3 platforms - pc, android and ios.[/background]

[/font]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]Angel script is awesome :)[/background]

[/font]

Advertisement
Great. That would definitely explain the empty module. :)


The call to SetEngineProperty(asEP_INIT_GLOBAL_VARS_AFTER_BUILD, 0) turns off the automatic initialization of the global variables. To manually initialize the variables after the build the method ResetGlobalVars() on the module must be called.

Normally this is not necessary, but there may be valid situations when the global variables shouldn't be initialized automatically. One is if you're building an offline compiler, i.e. an app that just compiles the scripts but don't execute them, another is if you want to add additional verifications on the build before initializing the variables.


Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement