examples/binding/lua/main.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file main.cpp
22 
23  \brief An example of usage of terralib binding lua module.
24  */
25 
26 // TerraLib
28 
29 // STL
30 #include <iostream>
31 #include <cstdlib>
32 
33 // Lua
34 #include <lua.hpp>
35 
36 int main(int /*argc*/, char** /*argv*/)
37 {
38  lua_State *L = luaL_newstate();
39 
40  luaopen_base(L);
41 
42  luaL_openlibs(L); /* Load Lua libraries */
43 
44  /* Load the file containing the script we are going to run */
45  std::string f = te::core::FindInTerraLibPath("share/terralib/examples/lua/geometry.lua");
46 
47  int status = luaL_loadfile(L, f.c_str());
48  if (status)
49  {
50 
51  std::cout <<std::endl <<"Couldn't load file: " <<lua_tostring(L, -1);
52  return EXIT_FAILURE;
53  }
54 
55  /* Ask Lua to run our little script */
56  int result = lua_pcall(L, 0, 0, 0);
57 
58  if(result)
59  {
60  std::cout <<std::endl <<"Failed to run script: " <<lua_tostring(L, -1);
61  getchar();
62 
63  return EXIT_FAILURE;
64  }
65 
66  lua_close(L);
67 
68  getchar();
69 
70  return EXIT_SUCCESS;
71 }
This file is a wrapper around platform specific include files.
int main(int, char **)
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.