-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlua_intf_common.h
84 lines (64 loc) · 2.99 KB
/
lua_intf_common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// Copyright 2015 by Kevin L. Goodwin [[email protected]]; All rights reserved
//
// This file is part of K.
//
// K is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// K is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with K. If not, see <http://www.gnu.org/licenses/>.
//
#pragma once
#include "ed_main.h"
#include "fname_gen.h"
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
// book http://www.lua.org/pil/
// file://c:/klg/sn/k/lua-5.1/doc/contents.html
// see http://www.allacrost.org/ (open-)source code for an example of cooperating Lua and C++ interface
extern "C"
{
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <k_lib.h>
}
static inline stref Sr_( lua_State *L, int n ) {
size_t length;
const auto data( luaL_checklstring( L, (n), &length ) );
if( !data ) return stref();
else return stref( data, length );
}
enum { DBG_LUA=0 };
//######### lua_edlib exports
extern void l_OpenStdLibs ( lua_State *L );
extern void l_register_EdLib( lua_State *L );
extern int l_construct_View( lua_State *L, PView pView );
extern int l_construct_FBUF( lua_State *L, PFBUF pFBuf );
extern int l_construct_Win ( lua_State *L, PWin pWin );
extern int l_View_function_cur( lua_State *L );
//######### utility externs
extern int LDS( PCChar tag, lua_State *L );
//######### common inlines
STIL PChar getfieldStrdup( lua_State *L, const char *key ) { lua_getfield(L, -1, key); PChar rv( Strdup( luaL_checkstring(L, -1) ) ); lua_pop(L, 1); return rv; }
STIL int getfieldInt( lua_State *L, const char *key ) { lua_getfield(L, -1, key); const int rv( luaL_checkint(L, -1) ) ; lua_pop(L, 1); return rv; }
STIL void setfield( lua_State *L, PCChar key, PCChar val ) { lua_pushstring( L, val ); lua_setfield( L, -2, key ); }
STIL void setfield( lua_State *L, PCChar key, int val ) { lua_pushinteger( L, val ); lua_setfield( L, -2, key ); }
STIL void setfield( lua_State *L, PCChar key, lua_CFunction val ) { lua_pushcfunction( L, val ); lua_setfield( L, -2, key ); }
STIL void setglobal( lua_State *L, PCChar key, PCChar val ) { lua_pushstring( L, val ); lua_setglobal( L, key ); }
STIL void setglobal( lua_State *L, PCChar key, int val ) { lua_pushinteger( L, val ); lua_setglobal( L, key ); }
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif