source: trunk/src/lib/lua.cc @ 165

Last change on this file since 165 was 165, checked in by epyon, 12 years ago
  • lua bindings - version choice made explicit, lua jit a toggle, not a version
File size: 1.8 KB
Line 
1// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
2// http://chaosforge.org/
3//
4// This file is part of NV Libraries.
5// For conditions of distribution and use, see copyright notice in nv.hh
6
7#include "nv/lib/lua.hh"
8
9#if defined( NV_LUA_DYNAMIC )
10
11#include "nv/library.hh"
12
13#if NV_LUA_VERSION == NV_LUA_52
14#       undef luaL_loadfile
15#       undef luaL_loadbuffer
16#       undef luaL_prepbuffer
17#       undef lua_tonumber
18#       undef lua_tointeger
19#       undef lua_tounsigned
20#       undef lua_call
21#       undef lua_pcall
22#       undef lua_yield
23#endif
24
25#define NV_LUA_FUN( rtype, fname, fparams ) rtype (*fname) fparams = nullptr;
26#if NV_LUA_VERSION == NV_LUA_52
27#       define NV_LUA_FUN_51( rtype, fname, fparams )
28#       define NV_LUA_FUN_52 NV_LUA_FUN
29#elif NV_LUA_VERSION == NV_LUA_51
30#       define NV_LUA_FUN_51 NV_LUA_FUN
31#       define NV_LUA_FUN_52( rtype, fname, fparams )
32#else
33#       define NV_LUA_FUN_51( rtype, fname, fparams )
34#       define NV_LUA_FUN_52( rtype, fname, fparams )
35#endif
36
37#include <nv/lib/detail/lua_functions.inc>
38
39#undef NV_LUA_FUN
40#undef NV_LUA_FUN_51
41#undef NV_LUA_FUN_52
42
43bool nv::load_lua_library( const char* path )
44{
45        static nv::library lua_library;
46        if ( lua_library.is_open() ) return true;
47        lua_library.open( path );
48
49#       define NV_LUA_FUN( rtype, fname, fparams ) *(void **) (&fname) = lua_library.get(#fname);
50#       if NV_LUA_VERSION == NV_LUA_52
51#               define NV_LUA_FUN_51( rtype, fname, fparams )
52#               define NV_LUA_FUN_52 NV_LUA_FUN
53#       elif NV_LUA_VERSION == NV_LUA_51
54#               define NV_LUA_FUN_51 NV_LUA_FUN
55#               define NV_LUA_FUN_52( rtype, fname, fparams )
56#       else
57#               define NV_LUA_FUN_51( rtype, fname, fparams )
58#               define NV_LUA_FUN_52( rtype, fname, fparams )
59#       endif
60
61#       include <nv/lib/detail/lua_functions.inc>
62
63#       undef NV_LUA_FUN
64#       undef NV_LUA_FUN_51
65#       undef NV_LUA_FUN_52
66        return true;
67}
68
69#endif
Note: See TracBrowser for help on using the repository browser.