PDA

View Full Version : PyroScript‚Ñ¢ v2.0



Pyrogine
10-02-2008, 02:22 AM
A new version of PyroScript coming soon. The new version now has Pascal/Delphi syntax with a simple and powerful API.

* Compiled script add-on for PyroGine (native code)
* Pascal/Delphi syntax
* Simple & powerful API
* Easily register native objects
* Easily access script define objects

This is the current API for PyroScript 2:
procedure Pyro_Script_Reset;
function Pyro_Script_RegisterNamespace(aLevelId: Integer; const aNamespace: PChar): Integer;
function Pyro_Script_RegisterRecordType(aLevelId: Integer; const aTypeName: PChar): Integer;
function Pyro_Script_RegisterRecordTypeField(aTypeId: Integer; const aFieldName: PChar; aFieldTypeID: Integer; aFieldShift: Integer = -1): Integer;
function Pyro_Script_RegisterHeader(aLevelId: Integer; const aHeader: PChar; aAddress: Pointer = nil; aMethodIndex: Integer = 0): Integer;
function Pyro_Script_RegisterClassType(aLevelId: Integer; aClass: TClass): Integer;
function Pyro_Script_RegisterProperty(aLevelId: Integer; const aHeader: PChar): Integer;
function Pyro_Script_RegisterVariable(aLevelId: Integer; const aVarName: PChar; aTypeId: Integer; aAddress: Pointer = nil): Integer;
function Pyro_Script_RegisterTypeAlias(aLevelId:Integer; const aTypeName: PChar; aOriginTypeId: Integer): Integer;
function Pyro_Script_RegisterPointerType(aLevelId: Integer; const aTypeName: PChar; aOriginTypeId: Integer): Integer;
procedure Pyro_Script_AddCodeFromFile(aSyntax: TPyroScriptSyntax; const aFilename: PChar);
procedure Pyro_Script_AddCodeFromArchive(aSyntax: TPyroScriptSyntax; aArchive: TPyroArchive; const aFilename: PChar);
function Pyro_Script_Compile: Boolean;
function Pyro_Script_Compiled: Boolean;
procedure Pyro_Script_Run;
function Pyro_Script_CreateObject(const aClassName: string): TObject;
procedure Pyro_Script_DestroyObject(aObject: TObject);
function Pyro_Script_GetHandle(aLevelId: Integer; const aMemberName: PChar; aCaseSensitive: Boolean): Integer;
function Pyro_Script_GetAddress(aLevelId: Integer; const aMemberName: PChar; aCaseSensitive: Boolean): Pointer;
function Pyro_Script_CallRoutine(aThis, aAddress: Pointer; const aParams: array of const; aCallConv: TPyroCallingConvention; aResult: TPyroResultType; aResultSize: Integer=0): Pointer;
function Pyro_Script_ErrorCount: Integer; stdcall;
function Pyro_Script_Error(aIndex: Integer): PChar;
function Pyro_Script_ErrorMessage(aIndex: Integer): PChar;
function Pyro_Script_ErrorModuleName(aIndex: Integer): PChar;
function Pyro_Script_ErrorLine(aIndex: Integer): PChar;
function Pyro_Script_ErrorLineNumber(aIndex: Integer): Integer;


Here is a simple example of how to load, compile, run and access script defined objects:
procedure native_msg(aMsg: PChar);
begin
MessageBox(0, aMsg, 'debug', MB_OK);
end;

var
Archive: Integer;
I: Integer;
Addr: Pointer;
begin
Archive := Pyro_UnzipArchive_Open('media.arc');

Pyro_Script_Reset;
Pyro_Script_RegisterHeader(0, 'procedure native_msg(s: string);', @native_msg);
Pyro_Script_AddCodeFromArchive(synPascal, Archive, 'media/scripts/simple.pas');
if Pyro_Script_Compile then
begin
Pyro_Script_Run;
Addr := Pyro_Script_GetAddress(0, 'script_msg', False);
if Assigned(Addr) then
begin
Pyro_Script_CallRoutine(nil, Addr, ['SWEET!'], ccREGISTER, rtVOID);
end;
end
else
begin
for I := 0 to Pyro_Script_ErrorCount - 1 do
begin
MessageBox(0, Pyro_Script_Error(I), 'debug', MB_OK);
end;
end;

Pyro_Object_Destroy(Archive);
end.


This a simple example script that is used in the example code above:
// simple script
procedure script_msg(aMsg: string);
var
s: string;
begin
s := 'Calling a script routine from native! ' + aMsg;
native_msg(PChar(s));
end;


begin
native_msg('Cool! Calling a native routine from script');
end.

You can even create an instance of a script defined class and call it's methods. I hope to post a beta build soon.

arthurprs
10-02-2008, 03:11 AM
Aren't you using Lua anymore?

Im currently working on a python scripting unit, and looking your methods gave me many ideas to do something similar

ps: The current pyrogine website are outdated :?

Pyrogine
10-02-2008, 04:14 AM
Not at this time, no. I really wanted to keep with a pascal/delphi syntax since it's my primary development language.

Oh your working on python scripting. Nice. Let me know if I can be of help. At some point I may release the source to my lua stuff.

Hmm... site is outdated for you? Tell me, what is the IP you get when you ping pyrogine.com? It maybe the DNS has not updated to your part of the world. Maybe your browser is picking up some cached IPs? Have you tried flushing your browser cache?

This is how the current site looks:

http://www.pyrogine.com/images/stories/products/website/website.png

arthurprs
10-02-2008, 04:20 AM
Yes exactly that website (66.6.102.192) but the last news are from july 2007 and there are no download stuff :?

you are right pascal syntax for scripting are aways welcome :) , but i'm python addicted :P

Pyrogine
10-02-2008, 04:41 AM
The IP should end in .193. The downloads, e-commerce, tutorials and the rest of the site will be back up soon. We've had some hacking issues that I've been dealing with so slowly bringing the site back online as we deal with this and some other problems. New builds should be released soon.

I wanted pascal syntax, the speed of native code and fast/easy interop between native and script. I wish you success with your python scripting solution. Things must be simple and easy to use yet robust. What I try to do is design from the end user perspective. Keep your API clean with minimal dependencies and be self subscribing.

arthurprs
10-02-2008, 05:36 AM
how can i get pyroscript 1.0 ? i really want it for inspiration :P

what are you using for native code, COCO ?

Pyrogine
10-02-2008, 06:52 AM
Check your PM.

Pyrogine
10-02-2008, 06:58 AM
Hmm... having some trouble posting. If you did not get my PM drop me an email.

arthurprs
10-02-2008, 07:09 AM
sorry but i forget your mail : mine is arthurprs(at)gmail(dot)com

Pyrogine
10-02-2008, 01:18 PM
Did you get my mail?

arthurprs
10-02-2008, 05:43 PM
Did you get my mail?

no :(

arthurprs
10-02-2008, 07:20 PM
function Py_Eval(const module, com, resultformat: string; const resultvalue: array of Pointer): Boolean;
var
pModule, pDict, pResult: PPyObject;
begin
Result := False;
pModule := PyImport_ImportModule(PChar(module));
if PyModule_Check(pModule) then
begin
pDict := PyModule_GetDict(pModule);
if PyDict_Check(pDict) then
begin
pResult := PyRun_String(PChar(com), eval_input, pDict, pDict);
if Assigned(pResult) then
begin
if PyArg_Parse&#40;pResult, PChar&#40;resultformat&#41;, resultvalue&#41; <> 0 then
Result &#58;= True;
Py_DECREF&#40;pResult&#41;;
end;
Py_DECREF&#40;pDict&#41;;// ERROR HERE, WHY ? Don't Know!
end;
Py_DECREF&#40;pModule&#41;;
end;
end;

im getting crazy with this stuff =.=

i tested exactly same code on C++ and works perfectly :roll:

Pyrogine
10-02-2008, 07:51 PM
no :(

Hmm... check your spam filter maybe?



im getting crazy with this stuff =.=

i tested exactly same code on C++ and works perfectly :roll:

Sweet!

arthurprs
10-02-2008, 08:05 PM
no :(

Hmm... check your spam filter maybe?
its not there ;/




im getting crazy with this stuff =.=

i tested exactly same code on C++ and works perfectly :roll:

Sweet!

i expressed myself wrong :lol:

it's bad, i don't know why im getting an error when dec dicts reference count :x

Py_DECREF&#40;pDict&#41;;// ERROR HERE, WHY ? Don't Know!

Pyrogine
10-02-2008, 08:40 PM
oh... ok. Hmmm.. let me see then... maybe the call to PyRun_String. I have no idea how it works. I see you pass pDict in twice? is that correct? Also maybe it does something to the ref count after it returns? What happens to ref count of pDict if PyRun_String fails?

arthurprs
11-02-2008, 01:43 AM
oh... ok. Hmmm.. let me see then... maybe the call to PyRun_String. I have no idea how it works. I see you pass pDict in twice? is that correct? Also maybe it does something to the ref count after it returns? What happens to ref count of pDict if PyRun_String fails?

a guy from google python group explained me the problem that is "borrowed" value, i must not dec it reference count and PyModule_GetDict returns a a borrowed value :?

all solved :)

Pyrogine
11-02-2008, 02:19 AM
Ah, good news.