Lua Projects
SunLicense Integration Guide for Lua Projects
Prerequisites
Integration Steps
1. Create License Validator
local socket = require("socket")
local http = require("socket.http")
local ltn12 = require("ltn12")
local json = require("dkjson")
local SunLicenseValidator = {}
SunLicenseValidator.__index = SunLicenseValidator
function SunLicenseValidator.new(licenseKey, productId, version)
local self = setmetatable({}, SunLicenseValidator)
self.licenseKey = licenseKey
self.productId = productId
self.version = version or "1.0.0"
self.apiUrl = "YOUR_API_URL/api/v1/validate"
return self
end
function SunLicenseValidator:validate()
local payload = {
licenseKey = self.licenseKey,
productId = self.productId,
productVersion = self.version,
hwid = self:getHWID() -- Optional
}
local jsonPayload = json.encode(payload)
local response = {}
local _, code = http.request{
url = self.apiUrl,
method = "POST",
headers = {
["Content-Type"] = "application/json",
["Content-Length"] = #jsonPayload
},
source = ltn12.source.string(jsonPayload),
sink = ltn12.sink.table(response)
}
if code ~= 200 then
error("License validation failed with code: " .. tostring(code))
end
return true
end
function SunLicenseValidator:getHWID()
-- Implement your HWID generation logic here
return "YOUR-HWID"
end2. Basic Implementation
3. Integration with LOVE2D (Game Framework)
Best Practices
Common Issues
Last updated