ouonline / luacpp Goto Github PK
View Code? Open in Web Editor NEWC++ bindings of Lua
License: BSD 3-Clause "New" or "Revised" License
C++ bindings of Lua
License: BSD 3-Clause "New" or "Revised" License
Thank you for your code. I am finding it useful. I have one question. I am trying to define a function on the C++ side that will be available on the lua side to compute the AND of a list of numbers. That requires looping thru every table element as follows.
auto AND = l.CreateFunction([](luacpp::LuaTable t) -> float
{
float result = t.GetNumber(1);
int i = 2;
// Size() is a function I wrote and added to luacpp
while (i <= t.Size())
{
result = result * t.GetNumber(i);
i++;
}
return result;
}, "AND");
If you note there is a Size() function here. I had to add that myself to lua_table.h/lua_table.cpp because I couldn't figure out how to loop thru every element of the table otherwise. I was previously using your ForEach() function like this along with a global variable called tCount defined outside the function scope.
// AND function. Same deal as or.
auto AND = l.CreateFunction([](luacpp::LuaTable t) -> float
{
// Function to check for lua table size. This is really bad coding but I
// dont know if my lua C++ wrapper can do it any other way.
tCount = 0;
auto iterfunc = [](const luacpp::LuaObject& key, const luacpp::LuaObject& value) -> bool
{
tCount++;
return true;
};
t.ForEach(iterfunc);
float result = t.GetNumber(1);
int i = 2;
while (i <= tCount)
{
result = result * t.GetNumber(i);
i++;
}
return result;
}, "AND");
I mean I have it working. But I figured you must have some intended way to do this that I just couldn't figure out.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.