Ela & C++

36 views
Skip to first unread message

Vadim Tukaev

unread,
Feb 10, 2014, 9:55:14 AM2/10/14
to ela...@googlegroups.com
Hello!

I want to use Ela as scripting langauge, similar to Lua or AngelScript. Is it possible? How to do it? I have to finish a DLL written in unmanaged C++, but I hate C++. How to embed Ela to such DLL?

By the way, this is my first program in Ela and it is crushes intimidating. I know, error is in last line: forgotten parentheses. However, the behavior of the Elide seemed to me inadequate. May be it's OK.

divisible_by_3_or_5 n =
  n `divisible_by` 3 || n `divisible_by` 5
  where divisible_by n m = n % m == 0

sum = foldl (+) 0

sum filter divisible_by_3_or_5 [1..1000]

ba...@voronkov.name

unread,
Feb 10, 2014, 10:42:43 AM2/10/14
to ela...@googlegroups.com

Hello, Vadim!

 

Ela itself is written in C# (100% pure and safe). You can use it in unmanaged language only through the wrapper (the wrapper can be written using C++/CLI for example), that would expose main Ela functions (such as compile, etc.) as DLL functions.

Another option for you may be to compile your DLL using C++/CLI which can do both managed and unmanaged. In that case Ela can be used as a simple library as in C#.

 

As for your code sample, when I run using the latest version of Ela I received the following error message (which is expected):

 

Error ELA820: 'isnil' is not implemented for the given argument list.

 

And no crushes. Can you send me the full text of your program?

 

Regards,

Basil.

--
 
---
You received this message because you are subscribed to the Google Groups "elalang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elalang+u...@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.

Vadim Tukaev

unread,
Feb 10, 2014, 1:52:25 PM2/10/14
to ela...@googlegroups.com
Another option for you may be to compile your DLL using C++/CLI which can do both managed and unmanaged. In that case Ela can be used as a simple library as in C#.

Thanks, but after reading the forums I got the impression that it is too difficult. Unfortunately, I'm a complete ignoramus in C++. :(

I have another idea. Can the Ela-program call functions from the C++ DLL? AFAIK, such technology named P/Invoke and available even in F#.

> And no crushes. Can you send me the full text of your program?

Apparently, it was not a crash. Sorry, I scared everyone, including himself.

ba...@voronkov.name

unread,
Feb 10, 2014, 2:00:36 PM2/10/14
to ela...@googlegroups.com

An ability to call native functions is not available by default, but it can be added using Ela foreign functions interface. There is a sample in the docs:

http://elalang.net/docs/Article.aspx?p=embedding.htm

The idea is – Ela calls a function in C# which then calls a native function. It would be a double marshalling though:

Ela types -> .NET types (done by Ela) and then .NET types -> native types (done by P/Invoke)

--

Vadim Tukaev

unread,
Feb 10, 2014, 2:22:30 PM2/10/14
to ela...@googlegroups.com
It is too complex. :( Better I decide this problem by using more appropriate languages, such as Gambit Scheme or newLisp. This does not mean that I reject the idea to explore Ela. That library is just one small task.

By the way, I got a real problem with Ela right now. I wrote a function that went into an infinite loop. I could not break it, because Elida stopped responding. I had to kill the process. By the time he ate half of my memory.

ba...@voronkov.name

unread,
Feb 10, 2014, 2:30:00 PM2/10/14
to ela...@googlegroups.com

Can you send me this function? Normally Elide would respond in such as case.

 

From: ela...@googlegroups.com [mailto:ela...@googlegroups.com] On Behalf Of Vadim Tukaev
Sent: Monday, February 10, 2014 11:23 PM
To: ela...@googlegroups.com
Subject: Re: Ela & C++

 

It is too complex. :( Better I decide this problem by using more appropriate languages, such as Gambit Scheme or newLisp. This does not mean that I reject the idea to explore Ela. That library is just one small task.



By the way, I got a real problem with Ela right now.

I wrote a function that went into an infinite loop. I could not break it, because Elida stopped responding. I had to kill the process. By the time he ate half of my memory.

--

Vadim Tukaev

unread,
Feb 11, 2014, 1:32:11 AM2/11/14
to ela...@googlegroups.com
fact x = x * fact (x - 1)

понедельник, 10 февраля 2014 г., 23:30:00 UTC+4 пользователь vorov2 написал:

ba...@voronkov.name

unread,
Feb 11, 2014, 2:12:31 AM2/11/14
to ela...@googlegroups.com

Я попробовал, Elide не завис, исполнение, конечно, долгое, но его можно остановить через Build->Stop Execution.

 

From: ela...@googlegroups.com [mailto:ela...@googlegroups.com] On Behalf Of Vadim Tukaev
Sent: Tuesday, February 11, 2014 10:32 AM
To: ela...@googlegroups.com
Subject: Re: Ela & C++

 

fact x = x * fact (x - 1)



понедельник, 10 февраля 2014 г., 23:30:00 UTC+4 пользователь vorov2 написал:

Can you send me this function? Normally Elide would respond in such as case.

--

Vadim Tukaev

unread,
Feb 11, 2014, 2:48:36 AM2/11/14
to ela...@googlegroups.com
May be problem in my system. I have Win7 installed on nettop with
single-core Intel Atom CPU.

ba...@voronkov.name

unread,
Feb 11, 2014, 3:24:08 AM2/11/14
to ela...@googlegroups.com
I see. That explains it. Looks like factorial calculation uses all CPU
resources and Elide freezes because of that.
Not sure how it can be helped. It is always possible to write code that
wouldn't terminate at all, e.g.:

force [1..]

In such a case Elide would need some CPU to remain responsive.
To be perfectly honest it was never tested on a single core CPU at all.
Reply all
Reply to author
Forward
0 new messages