next up previous contents
Next: 2. LuaCOM Elements Up: 1. Introduction Previous: 1.1 Features   Contents

1.2 How to use

Using LuaCOM is straightforward: you just have to link your program with LuaCOM's library, include the LuaCOM's header -- luacom.h -- and call the proper initialization and termination functions before using any of LuaCOM's functionalities. Here is an example of a simple C program using LuaCOM.
   /*
    * Sample C program using luacom
    */
   #include <stdio.h>
   #include <ole2.h> // needed for OleInitialize and OleUninitialize
   #include <lua.h>

   #include "luacom.h"

   int main (int argc, char *argv[]) {

     /* COM initialization */
     CoInitialize(NULL);

     /* library initialization */

     lua_State *L = lua_open(0);

     luacom_open(L);

     if(lua_dofile("activex_sample.lua") != 0) {
       puts("Error running sample.lua!");
       exit(1);
     }
     luacom_close(L);
     lua_close(L);

     CoUninitialize(NULL);
     return 0;
   }
Notice that it's necessary to initialize COM before luacom_open and to terminate it only after the last lua_close, otherwise faults may occur.

Vinicius da Silva Almendra 2003-06-04