I’ve completed a very barebone prototype that demonstrates how lua could be used to define iuse’s.
https://github.com/CIB/Cataclysm-DDA/commit/5c2ff27dadf92d05403a1bcbff203c667319ae9c
Example:
data/luamods/core/main.lua
-- Main mod file that will be executed by the game
-- at initialization time.
function hiccup(player, item, active)
game.add_msg("You hiccup.")
end
game.register_iuse("HICCUP", hiccup)
data/raw/items/tools.json
{ "id":"lighter",
"type": "TOOL",
"symbol": ",",
"color": "blue",
"name": "lighter",
"description": "A lighter must be carried to use various drugs, like cigarettes, or to light things like molotov cocktails. You can also use a lighter to light nearby items on fire.",
"rarity": 60,
"price": 35,
"material": ["plastic","iron"],
"weight": 0,
"volume": 0,
"bashing": 0,
"cutting": 0,
"to_hit": 0,
"max_charges": 100,
"initial_charges": 100,
"charges_per_use": 1,
"turns_per_charge": 0,
"ammo": "none",
"revert_to": "null",
"use_action": "HICCUP"
},
Now the lighter prints a hiccup message.
This is, as I said, still very bare-bones. There’s no way to access anything but game.add_msg(). Even the arguments to the iuse functions are currently nil, as I haven’t wrapped the player or item class in a lua object yet.
I’m not using any automatic binding generator. I’ve looked at tolua++, luabind and luna-gen, but all of them seemed too heavy weight to me or otherwise didn’t compile. All the bindings at the moment are hand-grafted, which doesn’t work too badly, though I suppose when it comes to wrapping accessors like item.name it will get annoying fast.
On the upside extra dependencies are thus minimal. On unix-like systems, lua 5.1 is easy to install. On other platforms, all that’s needed is downloading the lua source distribution and compiling it(lua is extremely portable, as it’s pure ANSI C).
Feedback welcome.