Search Unity

Is it possile to add CIL code to unity?

Discussion in 'Scripting' started by JohnSonLi, Jul 29, 2015.

  1. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    586
    or insert some cil code into C# code.....
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    like into the C# file?

    not really... why would you? Just write it in C#. CIL is any of the .net supported languages (like C#) compiled into its intermediate form. It's not intended to be written directly.

    If you mean you have some pre-compiled code in a dll (that would be CIL), you can definitely include it in your project.

    If you mean you want to generate code on the fly in the form of CIL opcodes, you can do this with the System.Reflection.Emit namespace. As long as you're not building for AOT, this can be done. I have a couple classes that actually do this (not mine directly, they're opensource and I'm using them):
    https://github.com/lordofduct/space...FastDynamicMemberAccessor/PropertyAccessor.cs
    https://github.com/lordofduct/space...s/FastDynamicMemberAccessor/MemberAccessor.cs


    What is this code anyways? Where did you get some CIL code just floating about that you need?
     
  3. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    It would likely help, if you could explain a little bit more about your actual use case? Are you still trying to look for a runtime code interpreter?
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    Oh yeah, JohnSonLi is the person trying to get an interpreter in C#.

    Which I already linked several options for that in the previous thread, but that it's not allowed on iOS (though some people sneak it in).

    If that's what you're trying to do. The Emit method can assist you in that... BUT, it too is NOT support on iOS. This time in the technical sense, and not just the rules sense. It straight up won't compile. Unlike the interpreters that work with things like Lua and javascript... which will compile (depending the library you use), but just aren't allowed on iOS.

    Long story short... interpreted code is not allowed on iphone. There is no getting around that, because even if you DID, Apple will take your app down if they find out its in there.
     
  5. JohnSonLi

    JohnSonLi

    Joined:
    Apr 15, 2012
    Posts:
    586
    an interpreter might not be a must I have been looking for, but I am new to mono and I want to learn more about it in a low level way......I am just a little bit curious......