giws a window for people using c/c++ into clojure ..

2 views
Skip to first unread message

Sunil S Nandihalli

unread,
Sep 8, 2010, 1:31:57 AM9/8/10
to clo...@googlegroups.com
Hello everybody,
 I recently came across giws


a tool to call java code from c/c++ all it really needs to generate all the jni-wrappers is a simple xml file which indicates the class name and the member functions .. some thing as simple as ...

<package name="example2">
  <object name="MyObjectWithArray">
        <method name="getMyString" returnType="String[]">
        </method>
        <method name="getMyInts" returnType="int[]">
        </method>
        <method name="doNothingPleaseButDisplay" returnType="void">
          <param type="int[]" name="plop" />
          <param type="short[]" name="plop2" />
        </method>
        <method name="setMyStrings" returnType="void">
          <param type="String[]" name="plop" />
        </method>
        <method name="dealingWithBooleans" returnType="boolean[]">
          <param type="boolean[]" name="plop" />
        </method>
  </object>
</package>

given clojure's power of macros .. it should be possible to automate the creation of this xml for every clojure-structure and function by redefining the defstruct and defn  and other similar macros .. I would like to give it a shot .. I am kind of new to all these things .. so would like to hear what the clojure community has to say about this...

Thanks in advance,
Sunil.

Sunil S Nandihalli

unread,
Sep 8, 2010, 5:12:41 AM9/8/10
to clo...@googlegroups.com
just as a followup .. this is the solution I got from hoek when I reposted it on the irc

(defn emit-giws-xml [c]
  (let [package (.getPackage c)
        methods (map #(hash-map :name (.getName %)
                                :returnType (str (.getName (.getReturnType %)))
                                :params (map (fn [p] {:name (.getName %)})
                                             (.getParameterTypes %)))
                     (.getMethods c))]
    methods
    ))

(clojure.pprint/pprint (emit-giws-xml Object))

Reply all
Reply to author
Forward
0 new messages