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; }
int tLuaCOMEnumerator::call_method(lua_State *L) { /// positions of parameters // self param (not used, but explicited to ensure // 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 enumerator_param = luaCompat_upvalueIndex(L, 1, 2); const int method_param = 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; // gets the enumerator tLuaCOMEnumerator* enumerator = (tLuaCOMEnumerator*) luaCompat_getTypedObject(L, enumerator_param); // gets the method name const char* method_name = lua_tostring(L, method_param); // call method int retval = 0; try { retval = enumerator->callCOMmethod(L, method_name, user_first_param, num_params); } catch(class tLuaCOMException& e) { luacom_error(L, e.getMessage()); return 0; } return retval; }
int tLuaCOMEnumerator::call_method(lua_State *L) { /// positions of parameters // self param (not used, but explicited to ensure // consistency) const int self_param = 1; // first user param const int user_first_param = 2; // last user param const int user_last_param = lua_gettop(L); // upvalues const int enumerator_param = lua_upvalueindex(1); const int method_param = lua_upvalueindex(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; // gets the enumerator tLuaCOMEnumerator* enumerator = (tLuaCOMEnumerator*)*(void **)lua_touserdata(L, enumerator_param); // gets the method name tStringBuffer method_name(lua_tostring(L, method_param)); // call method int retval = 0; try { retval = enumerator->callCOMmethod(L, method_name, user_first_param, num_params); } catch(class tLuaCOMException& e) { luacom_error(L, e.getMessage()); return 0; } return retval; }