Permalink
Browse files

First real commit.

  • Loading branch information...
1 parent 003fb85 commit fc536e9bf34465fbbe9d2fa0cf19a96ca50b2c3b @MaikBeckmann committed Apr 29, 2011
Showing with 805 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +7 −0 CMakeLists.txt
  3. +1 −0 README
  4. +26 −0 README.org
  5. +13 −0 src/CMakeLists.txt
  6. +107 −0 src/clua.c
  7. +324 −0 src/flua.f90
  8. +193 −0 src/lua_c_interfaces.f90
  9. +7 −0 test/CMakeLists.txt
  10. +20 −0 test/conf.lua
  11. +106 −0 test/test.f90
View
@@ -0,0 +1 @@
+*~
View
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 2.6)
+project(f2k3-lua C Fortran)
+
+find_package(Lua51 REQUIRED)
+
+add_subdirectory(src)
+add_subdirectory(test)
View
1 README
@@ -0,0 +1 @@
+TODO
View
@@ -0,0 +1,26 @@
+#+Title: f2k3 lua bindings - simple
+
+* What is meant by `simple'?
+This API proided in the `simple' branch of f2k3 is meant to serve the
+needs of using lua a language for configuration files and nothing
+else.
+
+* What can I do with it?
+After the configuration files was executed, you can query for
+variabes that hold the following data types
+ - strings
+ - sumbers
+ - Tables that are composed using numbers and strings
+
+
+* COMMENT Common build errors
+#+begin_src shell
+CMake Error at
+ /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:91
+ (MESSAGE): Could NOT find Lua51 (missing: LUA_LIBRARIES
+ LUA_INCLUDE_DIR) Call Stack (most recent call first):
+ /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:252
+ (_FPHSA_FAILURE_MESSAGE)
+ /usr/share/cmake-2.8/Modules/FindLua51.cmake:72
+ (FIND_PACKAGE_HANDLE_STANDARD_ARGS) CMakeLists.txt:4 (find_package
+#+end_src
View
@@ -0,0 +1,13 @@
+include_directories(
+ ${LUA_INCLUDE_DIR}
+)
+
+add_library(f2k3lua
+ clua.c
+ flua.f90
+ lua_c_interfaces.f90
+)
+
+target_link_libraries(f2k3lua
+ ${LUA_LIBRARIES}
+)
View
@@ -0,0 +1,107 @@
+#include <lua.h>
+#include <lauxlib.h>
+#include <lualib.h>
+#include <stdlib.h>
+
+
+void f2k3lua_stackDump(lua_State *L)
+{
+ int i;
+ int top = lua_gettop(L);
+ printf("stack: ");
+ for (i=1; i <= top; i++)
+ { /* repeat for each level */
+ int t = lua_type(L, i);
+ switch (t)
+ {
+ case LUA_TSTRING: /* strings */
+ printf("\"%s\"", lua_tostring(L, i));
+ break;
+
+ case LUA_TBOOLEAN: /* booleans */
+ printf(lua_toboolean(L, i) ? "true" : "false");
+ break;
+
+ case LUA_TNUMBER: /* numbers */
+ printf("%g", lua_tonumber(L, i));
+ break;
+
+ default: /* other values */
+ printf("%s", lua_typename(L, t));
+ break;
+
+ }
+ printf(" "); /* put a separator */
+ }
+ printf("\n"); /* end the listing */
+ fflush(stdout);
+}
+
+int f2k3lua_luaL_dofile(lua_State *L, char const *filename)
+{
+ return luaL_dofile(L, filename);
+}
+
+void dumpTable(lua_State* L, int idx)
+{
+ lua_pushnil(L); /* first key */
+ printf("start:\n");
+ while (lua_next(L, idx) != 0) {
+ /* `key' is at index -2 and `value' at index -1 */
+ printf("%s - %s\n",
+ lua_tostring(L, -2), lua_typename(L, lua_type(L, -1)));
+ lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */
+ }
+ printf("end\n");
+}
+
+
+void f2k3lua_lua_getglobal(lua_State *L, char const *k)
+{
+ lua_getglobal(L, k);
+}
+
+void f2k3lua_lua_setglobal(lua_State *L, char const *k)
+{
+ lua_setglobal(L, k);
+}
+
+char const* f2k3lua_luaL_checkstring(lua_State *L, int n)
+{
+ return luaL_checkstring(L, n);
+}
+
+
+int f2k3lua_lua_istable(lua_State *L, int n)
+{
+ return lua_istable(L, n);
+}
+
+
+void f2k3lua_lua_pop(lua_State *L, int n)
+{
+ lua_pop(L, n);
+}
+
+void f2k3lua_registersafeprint(lua_State *L, lua_CFunction safePrint)
+{
+ lua_pushcfunction(L, safePrint);
+ lua_setglobal(L, "print");
+}
+
+void f2k3lua_opensandboxlibs(lua_State *L)
+{
+ luaopen_base(L);
+ lua_pop(L, -1);
+ luaopen_table(L);
+ lua_pop(L, -1);
+ luaopen_string(L);
+ lua_pop(L, -1);
+ luaopen_math(L);
+ lua_pop(L, -1);
+}
+
+void f2k3lua_free(void* ptr)
+{
+ free(ptr);
+}
Oops, something went wrong.

0 comments on commit fc536e9

Please sign in to comment.