Recent

Author Topic: How make lib for PHP  (Read 5368 times)

usbdoo

  • New Member
  • *
  • Posts: 11
How make lib for PHP
« on: June 24, 2017, 08:10:47 am »
Quote
library TestLib;
{$mode objfpc}{$H+}
uses
  Classes;
  function ReturnPHP(aText:string) :string; cdecl;
  begin
    ReturnPHP:='Success   :'+aText;
  end;
  exports
    vrni;
  end.


In php I want to call the lazarus lib.

The question is?

Can this ReturnPHP use in PHP?
I would like this lib "ReturnPHP" to load in php and execute the function in PHP
Is this possible?

This lib is written correctly for use in PHP?

How to use lib and function in php?



« Last Edit: June 24, 2017, 09:57:39 am by usbdoo »

Фролов

  • New Member
  • *
  • Posts: 15
Re: How make lib for PHP
« Reply #1 on: June 24, 2017, 08:40:41 am »
Here there is something that interests you

https://github.com/NyaSik 


usbdoo

  • New Member
  • *
  • Posts: 11
Re: How make lib for PHP
« Reply #2 on: June 24, 2017, 10:01:54 am »

Delphy is calling php.
Is this true?


I need the reverse.
Php is calling lazarus lib?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How make lib for PHP
« Reply #3 on: June 24, 2017, 10:22:05 am »
Not that simple, unfortunately. PHP is one of the most complex language to write extension in. Here's a (C) tutorial:
https://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/

Even "Setting Up a Build Environment" might already let you down. You need a FULL PHP source code tree FOR A SPECIFIC VERSION (or several if you want to support multiple PHP version). Some efforts to simply the process for Pascal:
But neither is up to date with current PHP.

Python and Lua is a lot simpler in this regard, in which they only need calling convention to be fulfilled.

Фролов

  • New Member
  • *
  • Posts: 15
Re: How make lib for PHP
« Reply #4 on: June 24, 2017, 11:58:27 am »

Delphy is calling php.
Is this true?


I need the reverse.
Php is calling lazarus lib?

Yes


3DGAME php Result
https://s8.hostingkartinok.com/uploads/images/2017/06/8f33f116942b7a7dff4c4d9f5e9e0ffc.png


Code: PHP  [Select][+][-]
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="UTF-8">
  5.         <title></title>
  6.     </head>
  7.     <body>
  8.         <?php
  9.             echo phpversion();
  10.            
  11.        
  12. ?>
  13.     </body>
  14. </html>
  15.  
  16.        <?php
  17.      echo phpversion();
  18.  
  19. include_once "d3d.php";
  20.        
  21.         global $cam,$lit,$cub;
  22.        
  23.  
  24.        
  25.         b3d::bbBeginBlitz3D();
  26.  
  27.         b3d::bbGraphics3D(640,480,16,2);
  28.         b3d::bbAntiAlias( true );
  29.  
  30.         $World=b3d::bbCreatePlane(1, 0);
  31.         $World_Tex=b3d::bbLoadTexture('texture\11.jpg', 1);
  32.         b3d::bbScaleTexture ($World_Tex,3,3);
  33.         b3d::bbEntityTexture ($World,$World_Tex, 0, 0);
  34.         b3d::bbPositionEntity ($World,0,-5,0, 0);
  35.         b3d::bbScaleEntity($World, 0.5,0.5,0.5, 0);
  36.  
  37.         $Button=b3d::bbCreateCube(0);
  38.         b3d::bbScaleEntity ($Button,0.5,0.5,0.5, 0);
  39.         b3d::bbPositionEntity ($Button,1,0,4, 0);
  40.         $tex = b3d::bbLoadTexture('texture\botton.jpg', 1);
  41.         b3d::bbEntityTexture($Button,$tex, 0, 0);
  42.  
  43.         b3d::bbSetBuffer(b3d::bbBackBuffer());
  44.         $cam=b3d::bbCreateCamera(0);
  45.  
  46.         b3d::bbPositionEntity($cam,0,5,-10, 0);
  47.  
  48.         $lit=b3d::bbCreateLight(0, 0);
  49.         $cub=b3d::bbCreateCube(0);
  50.         $Cam=b3d::bbCreateCamera($cub);
  51.         $tex = b3d::bbLoadTexture('texture\2.jpg', 1);
  52.         b3d::bbEntityTexture($cub,$tex, 0, 0);
  53.        
  54.         while(true) {
  55.         global $cam,$lit,$cub;
  56.  
  57.  
  58.                         if (b3d::bbKeyDown(200))
  59.                            b3d::bbMoveEntity($cub,0,0,0.1);
  60.                         if (b3d::bbKeyDown(208))
  61.                            b3d::bbMoveEntity($cub,0,0,-0.1);
  62.                         if (b3d::bbKeyDown(203))
  63.                            b3d::bbTurnEntity($cub,0,1,0, 0);
  64.                         if (b3d::bbKeyDown(205))
  65.                            b3d::bbTurnEntity($cub,0,-1,0, 0);
  66.  
  67.  
  68.                         b3d::bbUpdateWorld(1);
  69.                         b3d::bbRenderWorld(1);
  70.                         b3d::bbText( 80,0,'П Е Р Е М Е Щ Е Н И Е  С Т Р Е Л К А М И ', 0, 0);
  71.                         b3d::bbText( 80,400,'Здоровье -  100%', 0,0 );
  72.                          b3d::bbText( 80,430,'Патроны 50\250', 0,0);
  73.                         b3d::bbFlip(1);
  74.         }
  75. ?>
  76.  


Code: PHP  [Select][+][-]
  1. <?php
  2.  
  3.  
  4. $b3dLib = new WinCBase('b3d', 'b3d.dll');
  5. $b3dLib->add(WinCBase::cdecl, 'int', 'bbVersion');
  6. $b3dLib->add(WinCBase::cdecl, 'void', 'bbSetBlitz3DDebugMode', 'int');
  7. $b3dLib->add(WinCBase::cdecl, 'void', 'bbSetBlitz3DHWND', 'int');
  8. $b3dLib->add(WinCBase::cdecl, 'void', 'bbSetBlitz3DTitle', 'PAnsiChar', 'PAnsiChar');
  9. $b3dLib->add(WinCBase::cdecl, 'int', 'bbBeginBlitz3D');
  10. $b3dLib->add(WinCBase::cdecl, 'int', 'bbBeginBlitz3DEx', 'int', 'int');
  11. ....
  12.  

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: How make lib for PHP
« Reply #5 on: June 27, 2017, 08:05:12 am »
I have been using this for years. It is also the basis for Delphi for PHP.
I will see if it compiles in FPC. Should be doable.
https://en.wikipedia.org/wiki/Php4delphi
http://users.telenet.be/ws36637/php4delphi.html

[OOPS] That is a lot of work.. But it is doable eventually. Maybe somebody already did this?
« Last Edit: June 27, 2017, 09:13:34 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How make lib for PHP
« Reply #6 on: June 30, 2017, 10:46:07 pm »
[OOPS] That is a lot of work.. But it is doable eventually. Maybe somebody already did this?
I've pointed PHP4Lazarus above, it's based on PHP4Delphi, just lagged behind it.

 

TinyPortal © 2005-2018