Choosing embedded scripting language for C++

前端 未结 6 1245
悲哀的现实
悲哀的现实 2021-02-06 03:16

I want to choose an embedded scripting language that i will use on C++. It should connect a database such as Oracle. My host application is a server application. That will pass

6条回答
  •  醉梦人生
    2021-02-06 03:41

    Save this as test.c:

    #include 
    
    int
    main(int argc, char *argv[])
    {
      Py_Initialize();
      PyRun_SimpleString("from time import time,ctime\n"
                         "print 'Today is',ctime(time())\n");
      Py_Finalize();
      return 0;
    }
    

    Run this command (if you have Python 2.7 installed):

    gcc test.c -o test -I/usr/include/python2.7 -lpython2.7

    Python has now been embedded. This took me under a minute, so I'm having a hard time understanding the claims of the "effort needed to embed it".

    The example is from http://docs.python.org/extending/embedding.html.

    I would suggest Python over Lua, even though Lua is also nice.

提交回复
热议问题