lua ~master
Lua bindings
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
luaexd
Lua bindings for DLang with extra wrappers.
Creating a new LuaState
To create a new LuaState you do newState()
, this will invoke the bindbc backend to bind lua as well return a new LuaState.
If lua is already bound, it will just return a new LuaState.
LuaState state = newState();
//create table
LuaTable table = state.newTable("MyGlobalTableName");
// Set "item" in table to "value"
table.set!string("item", "value");
state.executeString(q{
local val = MyGlobalTableName.item;
print(val);
});
(WIP) binding to classes
classes/structs that gets bound NEEDS an function with the signature void instantiate(Variant[] params)
.
Example (ManagedUserData!T):
class MyBoundClass {
// Pretty much the constructor.
// THIS WILL CHANGE IN THE FUTURE.
void instantiate(Variant[] params) {
// Empty constructor.
return;
}
@Expose
int meaningOfLife = 42;
@ExposeFunction
int getMeaningOfLife() {
return meaningOfLife;
}
@ExposeFunction
int getMeaningOfLifeTimes(int val) {
return meaningOfLife * val;
}
}
void main() {
LuaState state = newState();
ManagedUserData!MyBoundClass boundInstance = state.bindUserData!MyBoundClass;
state.executeString(q{
local classInstance = MyBoundClass()
// get value.
print(classInstance.meaningOfLife);
// call function.
print(classInstance.getMeaningOfLife());
// call function with parameters.
print(classInstance.getMeaningOfLifeTimes(2));
});
}
Example (mixin):
class MyBoundClass {
// Insert bindings.
mixin luaImpl!Element;
// Pretty much the constructor.
// THIS WILL CHANGE IN THE FUTURE.
void instantiate(Variant[] params) {
// Empty constructor.
return;
}
@Expose
int meaningOfLife = 42;
@ExposeFunction
int getMeaningOfLife() {
return meaningOfLife;
}
@ExposeFunction
int getMeaningOfLifeTimes(int val) {
return meaningOfLife * val;
}
}
void main() {
LuaState state = newState();
MyBoundClass classInstance = new MyBoundClass();
// Bind to lua.
classInstance.bindToLua(state);
state.executeString(q{
local classInstance = MyBoundClass()
// get value.
print(classInstance.meaningOfLife);
// call function.
print(classInstance.getMeaningOfLife());
// call function with parameters.
print(classInstance.getMeaningOfLifeTimes(2));
});
}
- Registered by Clipsey
- ~master released 5 years ago
- Member1221/luaexd
- MIT
- Copyright © 2019, Clipsey
- Authors:
- Dependencies:
- bindbc-loader
- Versions:
-
0.5.0 2019-Jan-20 ~master 2019-Jan-20 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
1 downloads this month
-
51 downloads total
-
- Score:
- 0.4
- Short URL:
- lua.dub.pm