Baskara Com Lua Embarcada
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
 
int main()
{
    int s=0;
 
    lua_State *L = lua_open();
 
    // load the libs
    luaL_openlibs(L);
 
    //run a Lua scrip here
    luaL_dofile(L,"baskara.lua");
 
    printf("\nI am done with Lua in C++.\n");
 
    lua_close(L);
 
    return 0;
}

**compilando

#g++ -o clua{,.cpp} -llua -ldl**

Lua Code

i = 1
while i == 1 do
    print("ax^2 + bx + c = 0")
    print("digite o termo a: ")
    a = io.read("*n")
    print("digite o termo b: ")
    b = io.read("*n")
    print("digite o termo c: ")
    c = io.read("*n")
    delta = math.pow(b,2) - 4*a*c
    if delta < 0 then
        print("Nao há raiz real, delta = "..delta)
        print("deseja resolver mais uma equacao? (1) sim (2) nao")
        i = io.read("*n")
    else
        x1 = (-b + math.pow(delta,(1/2)))/(2*a)
        x2 = (-b - math.pow(delta,(1/2)))/(2*a)
        print("x1 = "..x1..", x2 = "..x2..", delta = "..delta)
        print("deseja resolver mais uma equacao? (1) sim (2) nao")
        i = io.read("*n")    
    end
end

infos relevantes:

linux(umbutu)
sudo apt-get install liblua*
compilando
g++ -o clua{,.cpp} -llua -ldl

tutorial
http://cc.byexamples.com/20080607/how-to-embed-lua-51-in-c/
http://www.linuxmagazine.com.br/images/uploads/pdf_aberto/LM43_73-77.pdf

lua and c#
http://blog.apterainc.com/software/embedding-lua-and-c/

voltar

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.