Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es_extended/imports): add require #1567

Merged
merged 4 commits into from
Jan 1, 2025

Conversation

Kenshiin13
Copy link
Contributor

@Kenshiin13 Kenshiin13 commented Jan 1, 2025

Description

This PR introduces a new module loading system for the ESX framework. The require function is now available for importing resources, allowing them to load modules properly and efficiently, including those that define classes with metatables. This function includes caching to avoid redundant loads and circular dependency checks to prevent infinite loops.


Example Usage

--- resource1/modules/CStudent.lua
local Student = {}
Student.__index = Student

function Student.new(name, age)
	local self = setmetatable({}, Student)
	self.name = name
	self.age = age
	return self
end

function Student:getInfo()
	return ("Name: %s | Age: %d"):format(self.name, self.age)
end

return Student
--- resource2/server/main.lua
local CStudent = require("@resource1.modules.CStudent")

local student = CStudent.new("John Doe", 18)
print(student:getInfo()) -- Output: "Name: John Doe | Age: 18"

PR Checklist

  • My commit messages and PR title follow the Conventional Commits standard.
  • My changes have been tested locally and function as expected.
  • My PR does not introduce any breaking changes.
  • I have provided a clear explanation of what my PR does, including the reasoning behind the changes and any relevant context.

@Kenshiin13 Kenshiin13 self-assigned this Jan 1, 2025
@Kenshiin13 Kenshiin13 merged commit 452877c into esx-framework:dev Jan 1, 2025
1 check passed
@Kenshiin13 Kenshiin13 deleted the require branch January 1, 2025 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready for Next Update
Development

Successfully merging this pull request may close these issues.

2 participants