From 87c857a56b7703f976d3a5ef15967d80508df6e6 Mon Sep 17 00:00:00 2001 From: Andrew Kwon Date: Sun, 29 Jan 2023 01:21:17 -0800 Subject: [PATCH] Support configs that call setup using dot syntax Resolves (#90) --- README.md | 2 +- lua/presence/init.lua | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e2ee88c..c0e409e 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Require the plugin and call `setup` with a config table with one or more of the ```lua -- The setup config table shows all available config options with their default values: -require("presence"):setup({ +require("presence").setup({ -- General options auto_update = true, -- Update activity based on autocmd events (if `false`, map or manually execute `:lua package.loaded.presence:update()`) neovim_image_text = "The One True Text Editor", -- Text displayed when hovered over the Neovim image diff --git a/lua/presence/init.lua b/lua/presence/init.lua index 1c18a74..1d2aefe 100644 --- a/lua/presence/init.lua +++ b/lua/presence/init.lua @@ -68,7 +68,17 @@ local default_file_assets = require("presence.file_assets") local plugin_managers = require("presence.plugin_managers") local Discord = require("presence.discord") -function Presence:setup(options) +function Presence:setup(...) + -- Support setup invocation via both dot and colon syntax. + -- To maintain backwards compatibility, colon syntax will still + -- be supported, but dot syntax should be recommended. + local args = {...} + local options = args[1] + if #args == 0 then + options = self + self = Presence + end + options = options or {} self.options = options