Hi there. I've recently found Cobra. It is very interesting.
I am a python programmer from Linuxlandia so I'm not so cluey on .Net. I'd like to ask how I can make a program usable on Windows and on Linux if it wants to use things in Mono.Posix - ie: so that one binary can run on either operating system. In other words, can it at runtime figure out that it is on Linux and then dynamically load Mono.Posix somehow to use it's types?
And secondly, Chuck, can you clarify sharp strings?
You posted a post that says "Forget about sharp'foo' some time back. The current form is sharp('foo') and the old form is just there so code doesn't break."
But the latest code seems to all use the sharp'foo' version and 502-sharp.cobra shows $sharp('foo') as oldSyntax and appears to show sharp'foo' as current.
Of the three forms which is current and should be used? And are the others for other situations or deprecated?
Thanks lots,
Al
Forums
Conditionally referencing mono.
6 posts
• Page 1 of 1
Re: Conditionally referencing mono.
You can detect Mono with "CobraCore.isRunningOnMono". If the Mono.Posix.dll library behaves correctly on both platforms then you can just put it (and its dependencies) in the same directory as your .exe. I believe all those Mono libs are under the MIT license.
Otherwise, you can dynamically load a DLL using the System.Reflection namespace:
But I had some difficulties with Mono.Posix (I'm on Mono 2.6.4 on Mac OS X 10.6). When I tried .load('Mono.Posix.dll') I received an exception that it could not be found. I tried .load vs. .loadFrom and with the ".dll" extension and without. All failed. However, I can "use Mono.Posix" and also locate the file on disk, so it's definitely there. Finally, I used .loadWithPartialName which has been deprecated for a long time, but seems to be essential:
Note that when you dynamically load a DLL, your compiled program never had any static reference to it, so everything must be done dynamically.
So some work and research is required here to accomplish your goal of dynamically making posix calls that are not naturally supported on Windows, but having one executable. This would be true for any language. If Mono.Posix works on Windows, a static reference and distribution with your app is going to be the easiest route.
HTH
Otherwise, you can dynamically load a DLL using the System.Reflection namespace:
use System.Reflection
class Program
def main
a = Assembly.load('mscorlib.dll')
trace a
for type in a.getTypes, trace type
But I had some difficulties with Mono.Posix (I'm on Mono 2.6.4 on Mac OS X 10.6). When I tried .load('Mono.Posix.dll') I received an exception that it could not be found. I tried .load vs. .loadFrom and with the ".dll" extension and without. All failed. However, I can "use Mono.Posix" and also locate the file on disk, so it's definitely there. Finally, I used .loadWithPartialName which has been deprecated for a long time, but seems to be essential:
use System.Reflection
# assembly load methods are:
# .getLoadedModules, .load, .loadFile, .loadFrom, .loadModule,
# .loadWithPartialName, .reflectionOnlyLoad and .reflectionOnlyLoadFrom.
class Program
def main
a = Assembly.load('mscorlib.dll')
a = Assembly.loadWithPartialName('Mono.Posix')
trace a
# for type in a.getTypes, trace type
Note that when you dynamically load a DLL, your compiled program never had any static reference to it, so everything must be done dynamically.
So some work and research is required here to accomplish your goal of dynamically making posix calls that are not naturally supported on Windows, but having one executable. This would be true for any language. If Mono.Posix works on Windows, a static reference and distribution with your app is going to be the easiest route.
HTH
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Conditionally referencing mono.
I forgot to comment on "sharp".
The current approach is:
Please disregard other forms and previous posts.
Sorry for any confusion.
Hopefully you don't need it too often. The above in Cobra is "x += 1" unless you're dealing with a poorly designed library that exposes some functionality only through C#'s post-increment operator.
The current approach is:
sharp'x++'
# or with double quotes:
sharp"x++"
Please disregard other forms and previous posts.
Sorry for any confusion.
Hopefully you don't need it too often. The above in Cobra is "x += 1" unless you're dealing with a poorly designed library that exposes some functionality only through C#'s post-increment operator.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Conditionally referencing mono.
Timely, timely
See ticket:207 and patch for same.
See ticket:207 and patch for same.
- hopscc
- Posts: 632
- Location: New Plymouth, Taranaki, New Zealand
Re: Conditionally referencing mono.
Hey fellas,
I figured out that this works to load an assembly with Assembly.load(). The doco says you must supply a valid fully qualified assembly name.
Cheers
I figured out that this works to load an assembly with Assembly.load(). The doco says you must supply a valid fully qualified assembly name.
- Code: Select all
use System.Reflection
class Program
def main is shared
a = Assembly.load("Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756")
trace a
Cheers
call me Nev.
- nevdelap
- Posts: 61
- Location: Buenos Aires
Re: Conditionally referencing mono.
Ah, nice catch. I guess I was mislead by 'mscorlib.dll' working, so I didn't investigate the docs.
Also I was hoping to specify the simple name and get the latest version. Compilers themselves need such a capability because whether you use Cobra or C#, you can reference a library by its simple name and the compiler will find it.
Also I was hoping to specify the simple name and get the latest version. Compilers themselves need such a capability because whether you use Cobra or C#, you can reference a library by its simple name and the compiler will find it.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 77 guests