HTTPS clone URL
Subversion checkout URL
Example of Calling Lua from Fortran
FORTRAN Lua Makefile
Latest commit ec4b6f9 adolgert Merge pull request #1 from kmanalo/master …
Lua 5.2 Support. Lots of work. Proper attributions. Removal of TACC-specificity.
FortLua 5.2 ----------- This is a fork of a simple set of Lua bindings for use in Fortran, tested to be compatible with Lua 5.2.3+. Most of the original basis work is fully attributed to @adolgert and @adambrozier and creators of Aotus (see attribution clause) below. ==Motivation== This project shows how to call a Lua file from Fortran. You can also call a Lua file from C, but doing it from an even older language seems more dramatic. This also demonstrates how to call C libraries directly from Fortran using the iso_c_binding. ==Compilation== This project assumes that the Intel compiler suite and Lua are local to your path. On a machine with software modules support do the following: module load intel module load lua In your environment, `LUA_INC` and `LUA_LIB` must be predefined. Otherwise the Makefile is unhappy. ==Discussion== Why call Lua from Fortran? I can think of two good uses for this. Fortran's string parsing is not pretty, so you could use a Lua file as a configuration file. You can query environment variables and do pre-calculations in the configuration file, yielding a result for Fortran to use. You can even pass in functions for Fortran to execute. You could also write a commonly-modified subroutine in Lua so that there is no need to recompile the code when you make changes. Why Lua? The language is relatively simple and has basic math included. It's made to embed in programs. That said, it is not a common language. You could do the same exercise with Gnu Guile. How? Lua is a very small language that is built to be embedded. It passes all of its state back to the calling program through a stack (the stack data structure, but stored on the heap) so that it is simple to retrieve. We use Fortran's iso_c_binding to call the Lua C library directly from Fortran. That binding is a relatively new development in Fortran, but it works fine. Drew Dolgert email@example.com Adam Brazier firstname.lastname@example.org Kevin Manalo email@example.com This modification to FortLua was derived from routines provided by AOTUS, hence their attribution is listed below: Aotus License ------------- Aotus is licensed under the terms of the MIT license reproduced below. This means that Aotus is free software and can be used for both academic and commercial purposes at absolutely no cost. You are free to do with the code whatever you want. The only requirement is that some credit to the authors is given by putting this copyright notice somewhere in your project. The MIT license is chosen for full compatibility with Lua. For the license of the underlying Lua library have a look at http://www.lua.org/license.html. =============================================================================== Copyright (C) 2011-2013 German Research School for Simulation Sciences GmbH, Aachen and others. 2013-2015 University of Siegen. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ===============================================================================