Code Monkey home page Code Monkey logo

Comments (4)

volpi-m avatar volpi-m commented on September 24, 2024

Hello and thank you for trying to use my work.
I'm sorry, I realize the mistake I made, when you want to call a C++ function in Lua you have to use the lua API, so the add function in the example should look like this:

int add(lua_State *l)
{
    int n = lua_gettop(l); // get the number of arguments

    if (n != 2) {
        lua_pushliteral(l, "bad number of arguments");
        lua_error(l);
    }

    int a = lua_tointeger(l, 1); // get first argument
    int b = lua_tointeger(l, 2); // get second argument

    std::cout << "[C++] " << a << " + " << b << std::endl;
    lua_pushinteger(l, a + b); // the return value
    return 1; // number of argument returned
}

If you are at the root of the repository then you can compile that way:

make libluaincpp.a
g++ main.cpp -lluaincpp -lua -Isrc
./a.out

Tell me how it goes

from lua-in-cpp.

volpi-m avatar volpi-m commented on September 24, 2024

I updated the repository and provided a way to compile the README example, now you only have to do make test

from lua-in-cpp.

rohezal avatar rohezal commented on September 24, 2024

Thank you for the update, but I moved to sol3.

from lua-in-cpp.

volpi-m avatar volpi-m commented on September 24, 2024

Yeah, that's what I was afraid of 😅 The goal when I created this library was to have a simple way to call functions from one language to the other compared to sol3. If you're feeling adventurous you can try this library again 😊

from lua-in-cpp.

Related Issues (1)

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.