[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Functions with ACLs
- From: Hans Fuchs <hans@...>
- Date: Fri, 30 Aug 2002 17:21:12 +0200 (CEST)
Hi Everybody
I have the idea of a multi user extendable programm. For this programm
I have to be able to test if a user may call function y.x(). I made a test
programm using a "index" tagmethod.
See test programm below.
I put the functions as global table (object y) with a tag and no actual
functions defined. If a function (x) is executed, the tagmethod is
executed.
The tagmethod checks what function is executed and the users access
rights. If the user may access the function it is loaded from a datebase
in memory and is returned using a lua_dostring. If the user may not access
the function a generic function is returned which says that executing this
function isn't allowed.
By using this method I see a big performance problem, the function isn't
just once compiled when it is defined. It is compiled each time the
function is accessed. There for I thought I might use luac and
luab_dostring. So I would keep a already compiled version of the script
returning my function.
I would appreciate any comments or feedback. There are may be way better
or simplier methods.
Some questions:
Would using the precompiled script reach almost the same perfomance as a
normaly defined function?
Is anything to say against the trick using "return function()"?
Have I missed any problems?
Do you know a better method way?
Any better methods?
Ideas?
Best,
Hans
extern "C" {
#include "lua.h"
#include "lualib.h"
}
#include <stdio.h>
struct lua_State *L;
int intDoTag(lua_State *L);
int main(int argc, char* argv[])
{
int c;
L = lua_open(0);
lua_baselibopen(L);
int otag = lua_newtag(L);
// Set the tagmethod for the global object
lua_pushcfunction(L, intDoTag);
lua_settagmethod(L, otag, "index");
lua_newtable(L);
lua_settag (L, otag);
// Define a global object (table) to call functions on,
// no actual function defined.
lua_setglobal(L, "test");
// Start a test script
lua_dostring(L, "test.asdf(\"Hallo\")");
c = getc(stdin);
return 0;
}
int intDoTag(lua_State *L)
{
// Test if user may execute the funtion
// if yes, excute the funtion from a db (here hardcoded)
if(xxx)
{
lua_dostring(L, "return function (data)\nprint(data)\nend");
}
// if the user may not execute the funtion return a error
else
{
lua_dostring(L,
"return function (data)\nprint(\"Executing not allowed\")\nend");
}
return 1;
}