Skip to content

feat(es_extended/imports): add require#1567

Merged
Kenshiin13 merged 4 commits into
esx-framework:devfrom
Kenshiin13:require
Jan 1, 2025
Merged

feat(es_extended/imports): add require#1567
Kenshiin13 merged 4 commits into
esx-framework:devfrom
Kenshiin13:require

Conversation

@Kenshiin13

@Kenshiin13 Kenshiin13 commented Jan 1, 2025

Copy link
Copy Markdown
Contributor

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
@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