zephir icon indicating copy to clipboard operation
zephir copied to clipboard

CBLOCK docs...

Open IngwiePhoenix opened this issue 9 years ago • 7 comments

So I looked into Zephir for some code I am currently writing, and it poked me that Zephir is compiled to C. So I was like: Why can't I use C functions, then?

Answer: https://github.com/phalcon/zephir/blob/master/test/cblock.zep

Why is this not documented, like, at all? :/ When looking at zephir-lang website, I see no mention of this feature, which I think is VERY impressive.

IngwiePhoenix avatar Nov 28 '14 20:11 IngwiePhoenix

Mostly because it's not recommended, Zephir is unable to analyse the code inside c-blocks making the whole compiler useless. You only must use it if you need to do something that only works in C.

phalcon avatar Nov 28 '14 20:11 phalcon

So effectively, I can not use Zephir in order to build a C extension with a better OO layer? Oh… Because, I thought that this would be a really cool feature of Zephir - being able to create an OO wrapper of an existing API without all the zend hassle. The only other alternative is PHP-CPP, though…

Maybe Zephir will implement a similar feature in the future?

Am 28.11.2014 um 21:29 schrieb Phalcon [email protected]:

Mostly because it's not recommended, Zephir is unable to analyse the code inside c-blocks making the whole compiler useless. You only must use it if you need to do something that only works in C.

— Reply to this email directly or view it on GitHub https://github.com/phalcon/zephir/issues/654#issuecomment-64926546.

IngwiePhoenix avatar Nov 28 '14 20:11 IngwiePhoenix

Feel free to use the tool you think it's more appropriate for your work

phalcon avatar Nov 28 '14 20:11 phalcon

@IngwiePhoenix I am contributor of cblock and extern-libraries supports.

I am using Zephir to writing PHP Extensions that wrapper exists linux system calls and APIs.

Zephir supports Optimizers could do the same thinks to generate target c codes, and easier debugging for Zephir, you must consider it first.

And cblock only to be used at small codes, sometimes less than 10 lines for including c headers / define c struct , or declare c variables. Zephir Compiler (zep to c) can not analyse the code inside c-blocks, the warnings and errors are throws from Compiler (GCC / LLVM) ,but sometimes with 3rd libraries, there are over 100 lines warnings throws from GCC , that's why i say not easier for debugging. But, if you are C guys , this was piece of cake .

Here is the other one example of CURL php-extension written by Zephir (https://github.com/racklin/zephir-testcurl)

racklin avatar Nov 29 '14 00:11 racklin

@phalcon

Could we consider add a document for cblock and extern-libraries supports and with warning messages there are extreme features.

I can't found where to send document PR.

For cblock syntax: https://github.com/phalcon/zephir/pull/21 For extern-libraries syntax: https://github.com/phalcon/zephir/pull/636

Thanks .

racklin avatar Nov 29 '14 01:11 racklin

@phalcon @IngwiePhoenix cblock idea is inspired by golang cgo http://blog.golang.org/c-go-cgo

racklin avatar Nov 29 '14 01:11 racklin

@racklin

That example of using libcurl within Zephir is very awesome! I am glad your PRs got merged.

IngwiePhoenix avatar Nov 29 '14 13:11 IngwiePhoenix