Code Monkey home page Code Monkey logo

luacpp's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

luacpp's Issues

Size of LuaTable

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.