Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit f9ead87

Browse files
committed
add config options for renaming a bit of the magic
1 parent 55c91c4 commit f9ead87

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added `entry_name` config option (default: `__luapack_entry__`)
13+
- Added `package_preload_name` config option (default: `package.preload`)
14+
1015
### Fixed
1116

1217
- Fixed `package.searchpath` not being used in Lua 5.2+ (instead falling back to our implementation)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ All options:
176176
- `plugins = default_plugins` plugins
177177
- `compat_arg = true` compatibility for arg (cmd line arguments) passing in lua5.1 and 5.2
178178
- `include_entry = true` whether to include `__luapack_entry__` or not (useful for standalone packages)
179+
- `entry_name = "__luapack_entry__"` name of the entry function
180+
- `package_preload_name = "package.preload"` name of the package preload table
179181

180182

181183
- **Packer:searchpath_compat(name)**

luapack.yue

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,15 @@ if "table" == type moon
109109
-- plugins = default_plugins
110110
-- compat_arg = true
111111
-- include_entry = true
112+
-- entry_name = "__luapack_entry__"
113+
-- package_preload_name = "package.preload"
112114
export class Packer
113115
new: (@options = {}) =>
114116
@loaded = {}
115117

118+
_entry_name: => @options.entry_name or "__luapack_entry__"
119+
_package_preload_name: => @options.package_preload_name or "package.preload"
120+
116121
extract_packages: (source) =>
117122
matches = {n: 0}
118123
fast_push matches, match for _, match in source::gmatch require_pattern
@@ -148,10 +153,10 @@ export class Packer
148153
@include dependency for dependency in *@extract_packages @loaded[package_name]
149154

150155
pack: (entry) =>
151-
@include "__luapack_entry__", entry
152-
error "file not found: #{entry}" unless @loaded["__luapack_entry__"]?
156+
@include @_entry_name!, entry
157+
error "file not found: #{entry}" unless @loaded[@_entry_name!]?
153158

154-
@loaded["__luapack_entry__"] = nil if @options.include_entry == false
159+
@loaded[@_entry_name!] = nil if @options.include_entry == false
155160

156161
export: =>
157162
packed = @bootstrap!
@@ -198,9 +203,9 @@ export class Packer
198203
already_loaded = {}
199204
for package_name, content in pairs @loaded
200205
if already_loaded[content]
201-
writer::writeln "package.preload[%q] = package.preload[%q]"::format package_name, already_loaded[content]
206+
writer::writeln "%s[%q] = %s[%q]"::format @_package_preload_name!, package_name, @_package_preload_name!, already_loaded[content]
202207
else
203-
writer::writeln "package.preload[%q] = function(...)"::format package_name
208+
writer::writeln "%s[%q] = function(...)"::format @_package_preload_name, package_name
204209
writer::endwrap ->
205210
if @options.compat_arg != false and content::match "%.%.%."
206211
writer::writeln "local arg = __luapack_arg__"
@@ -209,14 +214,14 @@ export class Packer
209214
if @options.clear_loaded != false
210215
writer::writeln "package.loaded[%q] = nil"::format package_name
211216

212-
if @loaded["__luapack_entry__"]?
217+
if @loaded[@_entry_name!]?
213218
-- some C functions may return "fake" nil which behave differently
214219
-- returning it crashes some environments
215220
-- assigning it to a variable fixes the issue
216221
-- TODO: do we need the `do` block?
217222
writer::writeln "do"
218223
writer::endwrap ->
219-
writer::writeln 'local _result = package.preload["__luapack_entry__"](...)'
224+
writer::writeln 'local _result = %s[%q](...)'::format @_package_preload_name, @_entry_name!
220225
writer::writeln "return _result"
221226
writer::str!
222227

0 commit comments

Comments
 (0)