Lua Projects
SunLicense Integration Guide for Lua Projects
Prerequisites
Lua 5.1 or higher
LuaSocket library
JSON library (dkjson or similar)
SunLicense API credentials
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
Error Handling
Use pcall for error handling
Implement proper logging
Handle network timeouts
Security
Secure storage of license key
Implement HTTPS communication
Handle sensitive data carefully
Performance
Cache validation results
Implement retry logic
Handle offline scenarios
Common Issues
Network Problems
Implement timeout handling
Add retry logic
Handle connection errors
SSL/HTTPS Issues
Configure proper SSL certificates
Handle HTTPS requirements
Verify API endpoint security
JSON Parsing
Handle malformed responses
Validate response format
Proper error handling
Last updated