Lua is rarely the language a product is written in. It is the language a product is extended in: a CAD package, a simulator, an instrument’s scripting host, a game engine. That makes it the natural place to license a paid plugin or add-on — and the place where a licence check is most exposed, because the script usually ships as readable source alongside the application.
The binding is one file using LuaJIT’s ffi module, so there is nothing to compile and nothing to install. Plain Lua 5.x has no FFI and would need a C extension module, which defeats the point.
Reading a license
local keynub = require('keynub_licdongle')
local ctx = keynub.Context()
local dongle = ctx:open() -- first dongle, or ctx:open(serial)
dongle:verifyGenuine() -- errors unless genuine
local session = dongle:openSession()
local license = session:readRecord('license')
session:close(); dongle:close(); ctx:close()Code language: Lua (lua)
Why the boolean is worst here
In a compiled product, removing a licence check means patching a binary. In a Lua add-on it means opening a file in a text editor:
-- Anyone who bought your add-on can delete this line.
if not licensed then os.exit() endCode language: Lua (lua)
So do not write it. Encrypt what the add-on needs — its geometry kernels, rule tables, post-processor definitions, the parameters that make it worth paying for — and decrypt them through the dongle when the plugin loads:
local rules = session:appDecrypt(blob) -- shipped encrypted with the add-onCode language: Lua (lua)
Two practical notes
Byte data is a Lua string throughout, which is what ffi.string produces and what #s measures correctly for binary. And progress callbacks are freed explicitly after use: LuaJIT allocates a machine-code trampoline per ffi.cast of a function and they are a finite resource, so a long-running host that never freed them would eventually run out. The binding handles that for you.
Code
Runnable sample: lua/verify_and_read.lua. Binding source: bindings/lua. Both are Apache-2.0, in the public SDK repository; the prebuilt native library is attached to each release.
All supported languages · All industries · Buy a KeyNub · Ask us something