-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Lua interpreter in augtool #300
Open
raphink
wants to merge
52
commits into
hercules-team:master
Choose a base branch
from
raphink:lua
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
10bd64a
Add a lua interpreter to augtool
raphink 0bf4760
Use snprintf in lua_checkargs
raphink fac868b
Allow nil as third value in defnode
raphink 22d60f5
Make auto_save work with lua
raphink 4e7ea58
Add lua_aug_clear, lua_aug_clearm and lua_aug_touch
raphink 9127af5
Remove comment
raphink 18ef0fc
Continue on empty lines in lua
raphink 3f4ead5
Make multiline work in lua REPL, irb style
raphink b351999
Make command as arg work with lua
raphink f8eeb22
Lua aliases for store/retrieve
raphink 70e68d1
Pass arguments to lua script
raphink 0f5851f
Use an aug table to assign lua methods
raphink ef23c22
Put lua code in src/auglua.c
raphink 89abf80
Cleanup code
raphink 74227f2
Rename setup_lua to luaopen_augeas
raphink ea2daf2
Reset Menu.txt
raphink 1ebed13
Newlines DO work
raphink 029b60d
Add aug_lua
raphink 9b30c76
Use a better registry key
raphink 731466e
better var name
raphink 94a577f
Reset etc/passwd in root
raphink 8c4d38d
Revert "Reset etc/passwd in root"
raphink 3c11069
AUGEAS_0.21.0
raphink 03b95f3
Remove unnecessary comments
raphink 382e55f
Use lua_pushfstring
raphink bd23da0
Fix call of run_command()
raphink b40abf4
configure: scan for Lua versions
kunkku 219dff8
move Lua extensions to libauglua
kunkku acbde1e
import laugeas.c from lua-augeas as luamod
kunkku c2e3a3b
luamod: add copyright notice
kunkku 8ce7857
compile luamod
kunkku 4afe954
rename luaopen_augeas back to setup_lua
kunkku 6c17a37
luamod: define public interface
kunkku 433ee86
luamod: userdata structure
kunkku f69a357
auglua: use lua_pushliteral with registry key
kunkku 5886de4
auglua: use luamod to push instance to stack
kunkku 682cd10
auglua: use luamod for missing functions
kunkku fc0c812
auglua: remove redundant functions
kunkku 02624ef
auglua: move label to luamod
kunkku 2b3d9e9
auglua: move cp to luamod
kunkku 60f28b2
auglua: move rename to luamod
kunkku f6350cb
auglua: move clear to luamod
kunkku 7d291e1
auglua: move clearm to luamod
kunkku 3de1ad5
auglua: move touch to luamod
kunkku 01778a8
auglua: move text_store to luamod
kunkku a3948ef
auglua: move text_retrieve to luamod
kunkku 5ed0705
auglua: move transform to luamod
kunkku 5967264
auglua: save: use luamod functions
kunkku 7a402e3
make Lua module for all available versions
kunkku 0908334
Merge pull request #1 from kunkku/lua-combined
raphink c04faa6
include config.h in auglua.c and luamod.c
kunkku d3210af
Merge pull request #2 from kunkku/lua-include-config
raphink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ addons: | |
packages: | ||
- libxml2-dev | ||
- libreadline-dev | ||
- liblua5.2-dev | ||
- valgrind | ||
install: | ||
- ./autogen.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (C) 2016 Kaarle Ritvanen | ||
|
||
AUTOMAKE_OPTIONS = subdir-objects | ||
|
||
LUA_PACKAGE = $(notdir $(CURDIR)) | ||
|
||
luadir = $(libdir)/lua/$(shell $(PKG_CONFIG) --variable=V $(LUA_PACKAGE)) | ||
lua_LTLIBRARIES = augeas.la | ||
|
||
augeas_la_SOURCES = ../augeas.h ../luamod.c ../luamod.h | ||
augeas_la_CFLAGS = $(AM_CFLAGS) $(LIBXML_CFLAGS) $(shell $(PKG_CONFIG) --cflags $(LUA_PACKAGE)) | ||
augeas_la_LIBADD = ../libaugeas.la | ||
augeas_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version -module -shared |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* auglua.c: lua integration for augtool | ||
* | ||
* Copyright (C) 2015 Raphaël Pinson | ||
* Copyright (C) 2016 Kaarle Ritvanen | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library 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 | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
* | ||
* Author: Raphaël Pinson <[email protected]> | ||
*/ | ||
|
||
#include <config.h> | ||
#include "internal.h" | ||
#include "augeas.h" | ||
#include "luamod.h" | ||
#include "auglua.h" | ||
#include <lua.h> | ||
#include <lualib.h> | ||
#include <lauxlib.h> | ||
#include <stdbool.h> | ||
|
||
|
||
#define REG_KEY_MODULE "augeas-module" | ||
#define REG_KEY_INSTANCE "augeas-instance" | ||
|
||
static void push_reg_value(lua_State *L, const char *key) { | ||
lua_pushstring(L, key); | ||
lua_gettable(L, LUA_REGISTRYINDEX); | ||
} | ||
|
||
static int call_function(lua_State *L, const char *name) { | ||
push_reg_value(L, REG_KEY_MODULE); | ||
lua_pushstring(L, name); | ||
lua_gettable(L, -2); | ||
lua_insert(L, 1); | ||
|
||
push_reg_value(L, REG_KEY_INSTANCE); | ||
lua_insert(L, 2); | ||
|
||
lua_call(L, lua_gettop(L) - 1, LUA_MULTRET); | ||
return lua_gettop(L); | ||
} | ||
|
||
static int call_bound_function(lua_State *L) { | ||
int vals = call_function(L, lua_tostring(L, lua_upvalueindex(1))); | ||
if (lua_isnil(L, 1) && lua_isstring(L, 2)) { | ||
lua_pushvalue(L, 2); | ||
lua_error(L); | ||
} | ||
return vals; | ||
} | ||
|
||
static int bind_function(lua_State *L) { | ||
lua_pushcclosure(L, call_bound_function, 1); | ||
return 1; | ||
} | ||
|
||
static int lua_aug_save(lua_State *L) { | ||
int n; | ||
|
||
call_function(L, "save"); | ||
|
||
if (lua_isnil(L, 1)) { | ||
lua_pushstring(L, "saving failed (run 'errors' for details)"); | ||
lua_error(L); | ||
} else { | ||
lua_settop(L, 0); | ||
lua_pushliteral(L, "/augeas/events/saved"); | ||
call_function(L, "match"); | ||
|
||
if (!lua_isnil(L, 1)) { | ||
n = (int) lua_tointeger(L, 2); | ||
if (n > 0) | ||
printf("Saved %d file(s)\n", n); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
struct lua_State *setup_lua(augeas *a) { | ||
lua_State *L = luaL_newstate(); | ||
luaL_openlibs(L); | ||
|
||
lua_pushliteral(L, REG_KEY_MODULE); | ||
luaopen_augeas(L); | ||
lua_settable(L, LUA_REGISTRYINDEX); | ||
|
||
lua_pushliteral(L, REG_KEY_INSTANCE); | ||
luamod_push_augeas(L, a); | ||
lua_settable(L, LUA_REGISTRYINDEX); | ||
|
||
static const luaL_Reg augfuncs[] = { | ||
//{ "span", lua_aug_span }, | ||
{ "save", lua_aug_save }, | ||
//{ "escape_name", lua_aug_escape_name }, | ||
//{ "to_xml", lua_aug_to_xml }, | ||
//{ "errors", lua_aug_errors }, | ||
{ NULL, NULL } | ||
}; | ||
|
||
luaL_newlib(L, augfuncs); | ||
|
||
static const luaL_Reg meta[] = {{"__index", bind_function}, {NULL, NULL}}; | ||
luaL_newlib(L, meta); | ||
lua_setmetatable(L, -2); | ||
|
||
lua_setglobal(L, "aug"); | ||
|
||
return L; | ||
} | ||
|
||
int aug_lua(lua_State *L, const char *text) { | ||
int code = luaL_loadbuffer(L, text, strlen(text), "line") || lua_pcall(L, 0, 0, 0); | ||
return code; | ||
} | ||
|
||
|
||
/* | ||
* Local variables: | ||
* indent-tabs-mode: nil | ||
* c-indent-level: 4 | ||
* c-basic-offset: 4 | ||
* tab-width: 4 | ||
* End: | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* auglua.h: Lua helper lib for Augeas | ||
* | ||
* Copyright (C) 2015 Raphaël Pinson | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library 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 | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
* | ||
* Author: Raphaël Pinson <[email protected]> | ||
*/ | ||
#include <lua.h> | ||
|
||
#ifndef AUGLUA_H_ | ||
#define AUGLUA_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct lua_State *setup_lua(augeas *a); | ||
|
||
int aug_lua(lua_State *L, const char *text); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif | ||
|
||
/* | ||
* Local variables: | ||
* indent-tabs-mode: nil | ||
* c-indent-level: 4 | ||
* c-basic-offset: 4 | ||
* tab-width: 4 | ||
* End: | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
AUGLUA_0.0.0 { | ||
global: | ||
setup_lua; | ||
aug_lua; | ||
local: *; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the rest of the project written in C++, or why are you adding this protective
extern
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of augeas has that, I suppose to allow using the lib in c++
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functions in
auglua.h
aren't meant to become part of the public augeas API, or are they ? I.e., when would somebody else writeinclude "auglua.h"
in their source ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to expose an
aug_lua
call, which would allow e.g. Puppet to take lua commands in theaugeas
type?