private LuaDataContainer GetContainerCore(LuaTable obj, bool protectFromGC = false) { // Does this have a ClassName? // Yes -> Returns the Wherigo object's data container. // (This allows the registration process to take place.) // No -> Creates and returns the container. LuaDataContainer ret; string cn = _luaState.SafeGetField <string>(obj, "ClassName"); if (cn != null) { ret = (LuaDataContainer)GetWherigoObjectCore(obj, forceProtectFromGC: protectFromGC).DataContainer; } else { ret = CreateContainerCore(obj, protectFromGC); } return(ret); }
/// <summary> /// Calls a function from this container for a particular key and /// with particular arguments. /// </summary> /// <param name="key">The key to find the function at.</param> /// <param name="parameters">Optional parameters to pass to the function. /// The native lua table will be added as first parameter before calling /// the function.</param> /// <returns>The first data container that is returned by the function, /// or null if none were.</returns> internal LuaDataContainer CallSelf(string key, params object[] parameters) { // Gets the function at the key. LuaFunction lf = _luaState.SafeGetField <LuaFunction>(_luaTable, key); // Checks if the function exists. if (lf == null) { throw new InvalidOperationException("The function " + key + " does not exist."); } // Gets a provider for the function and calls it. LuaDataProvider provider = _dataFactory.GetProvider(lf, this, false); return(provider.FirstContainerOrDefault(parameters)); }