Beispiel #1
0
int tLuaObject::closure(lua_State *L)
{
  tLuaObjectMethod method = (tLuaObjectMethod) 
    luaCompat_getPointer(L, lua_upvalueindex(1));

  tLuaObject* lua_obj = getObject(L, 1);

  if(lua_obj == NULL)
  {
    luacom_error(L, "Error: self parameter is not a tLuaObject.");
    return 0;
  }

  int retval = 0;

  try
  {
    retval = method(lua_obj, L);
  }
  catch(class tLuaCOMException& e)
  {
    luacom_error(L, e.getMessage());

    return 0;
  }

  return retval;
}
Beispiel #2
0
static tLuaCOMClassFactory* factoryCache_GetFactory(const char* luaclsid) {
  CriticalSectionObject cs(&cs_factoryCache); // won't let other threads enter till it goes out of scope
  lua_getglobal(factoryCache,"factories");
  lua_pushstring(factoryCache,luaclsid);
  lua_gettable(factoryCache,-2);
  tLuaCOMClassFactory* pFactory = (tLuaCOMClassFactory*)luaCompat_getPointer(factoryCache,-1);
  lua_pop(factoryCache,2);
  return pFactory;
}
Beispiel #3
0
static void factoryCache_Release() {
  CriticalSectionObject cs(&cs_factoryCache); // won't let other threads enter till it goes out of scope
  lua_getglobal(factoryCache,"factories");
    lua_pushnil(factoryCache); 
    while(lua_next(factoryCache,-2) != 0) {
    tLuaCOMClassFactory* pFactory = (tLuaCOMClassFactory*)luaCompat_getPointer(factoryCache,-1);
    pFactory->Release();
    lua_pop(factoryCache,1);
    }
  lua_pop(factoryCache,1);
  #ifdef IUP
    IupClose();
  #endif
}
void LuaAux::printLuaStack(lua_State *L)
{
  int size = lua_gettop(L);
  int i = 0;

  for(i = size; i > 0; i--)
  {
    switch(lua_type(L,i))
    {
    case LUA_TNUMBER:
      printf("%d: number = %d", i, lua_tonumber(L, i));
      break;

    case LUA_TSTRING:
      printf("%d: string = \"%s\"", i, lua_tostring(L, i));
      break;

    case LUA_TTABLE:
      printf("%d: table, tag = %d", i, luaCompat_getType2(L, i));
      break;

    case LUA_TUSERDATA:
      printf("%d: userdata = %p, tag = %d", i,
        (long) luaCompat_getPointer(L, i), luaCompat_getType2(L, i));
      break;

    case LUA_TNIL:
      printf("%d: nil", i);
      break;

    case LUA_TBOOLEAN:
      if(lua_toboolean(L, i))
        printf("%d: boolean = true", i);
      else
        printf("%d: boolean = false", i);

      break;

    default:
      printf("%d: unknown type (%d)", i, lua_type(L, i));
      break;
    }      

    printf("\n");
  }

  printf("\n");
}
tLuaCOMClassFactory::tLuaCOMClassFactory(lua_State* L)
{
  CHECKPARAM(L);

  m_cRef = 0;

  L_inproc = L;
  lua_getregistry(L);
  lua_pushstring(L,"object");
  lua_gettable(L,-2);
  object = (IDispatch*)luaCompat_getPointer(L,-1);
  object->AddRef();
  lua_pop(L,1);
  lua_pushstring(L,"object");
  lua_pushnil(L);
  lua_settable(L,-3);
  lua_pop(L,1);
}
// lua C function that dispatches events
// to sinks
int tLuaCOMConnPoint::call_sinks(lua_State *L)
{
  /// positions of parameters
  
  // self param (not used, but needed for ensuring
  // consistency
  const int self_param        = 1;

  // first user param 
  const int user_first_param  = 2;
  
  // last user param, excluding upvalues
  const int user_last_param   = luaCompat_getNumParams(L, 2);

  // upvalues
  const int connpoint         = luaCompat_upvalueIndex(L, 1, 2);
  const int event             = luaCompat_upvalueIndex(L, 2, 2);

  int num_params = 0;

  if(user_last_param < user_first_param)
    num_params = 0;
  else
    num_params = user_last_param - user_first_param + 1;

  // counter
  int i = 0;
   
  // gets connection point
  tLuaCOMConnPoint* cp = 
    (tLuaCOMConnPoint*) luaCompat_getPointer(L, connpoint);

  // call each sink
  for(i = 0; i < (int)cp->cConnections; i++)
  {
    // pushes function
    LuaBeans::push(L, cp->sinks[i]);
    cp->sinks[i]->Lock();

    lua_pushvalue(L, event);
    lua_gettable(L, -2);
    
    // removes table, leaving just function
    lua_remove(L, -2);

    // self param (mandatory but unused)
    LuaBeans::push(L, cp->sinks[i]);
    cp->sinks[i]->Lock();

    // duplicates parameters (if any)
    for(i = user_first_param; i <= user_last_param; i++)
    {
      lua_pushvalue(L, i);
    }

    // calls function (including self param)
    // ignoring errors
    luaCompat_call(L, num_params+1, 0, NULL);

    // cleans stack
    lua_settop(L, user_last_param);
  }

  // events do not return nothing
  return 0;
}