示例#1
0
static void pushresult(int32 i) {
	if (i)
		lua_pushuserdata(0);
	else {
		lua_pushnil();
		lua_pushstring("File I/O error.");
	}
}
示例#2
0
void LuaMachine::releaseUserdata(void* userdata)
{
    lua_getfield(L, LUA_REGISTRYINDEX, "UDATA"); // T
    lua_pushuserdata(L, userdata); // TK
    lua_pushnil(L); // TKV
    lua_rawset(L, -3); // T
    lua_pop(L, 1); //
}
示例#3
0
void LuaMachine::retainUserdata(void* userdata)
{
    lua_getfield(L, LUA_REGISTRYINDEX, "UDATA"); // T
    lua_pushuserdata(L, userdata); // TK
    lua_pushboolean(L, true); // TKV
    lua_rawset(L, -3); // T
    lua_pop(L, 1); //
}
示例#4
0
void Lua_V1::Remove() {
	if (g_system->getSavefileManager()->removeSavefile(luaL_check_string(1)))
		lua_pushuserdata(0);
	else {
		lua_pushnil();
		lua_pushstring(g_system->getSavefileManager()->getErrorDesc().c_str());
	}
}
示例#5
0
static void GetAttributeData(void)
{
  char *value = IupGetAttribute(iuplua_checkihandle(1), luaL_check_string(2));
  if (value)
    lua_pushuserdata((void*)value);
  else
    lua_pushnil();
}
示例#6
0
static void GetGlobal(void)
{
  const char* a = luaL_check_string(1);
  char *v = IupGetGlobal(a);
  if (iupGlobalIsPointer(a))
    lua_pushuserdata((void*)v);
  else
    lua_pushstring(v);
}
示例#7
0
文件: liolib.c 项目: jeske/hz
static void pushresult (int i)
{
  if (i)
    lua_pushuserdata(NULL);
  else {
    lua_pushnil();
    lua_pushstring(strerror(errno));
  }
}
示例#8
0
static void luaB_dostring (void) {
  long l;
  char *s = luaL_check_lstr(1, &l);
  if (*s == ID_CHUNK)
    lua_error("`dostring' cannot run pre-compiled code");
  if (lua_dobuffer(s, l, luaL_opt_string(2, s)) == 0)
    if (luaA_passresults() == 0)
      lua_pushuserdata(NULL);  /* at least one result to signal no errors */
}
示例#9
0
static int pushresult (lua_State *L, int i) {
  if (i) {
    lua_pushuserdata(L, NULL);
    return 1;
  }
  else {
    lua_pushnil(L);
    lua_pushstring(L, strerror(errno));
    lua_pushnumber(L, errno);
    return 3;;
  }
}
示例#10
0
int InitScripting(DISZ80 *d)
{
	char	buf[256];
	int		err;

	if (d->ls == NULL)
		{
		d->ls = lua_open(0);

		if (d->ls == NULL)
			return DERR_OUTOFMEM;
		
		lua_baselibopen(d->ls);
		lua_strlibopen(d->ls);

		lua_pushuserdata(d->ls, d);
		lua_setglobal(d->ls, "DISZ80STRUC");

		lua_register(d->ls, LUA_ERRORMESSAGE, LuaErrorHandler);

/* Register the dZ80 support functions */
		lua_register(d->ls, "d_RegTrap",		d_RegTrap);
		lua_register(d->ls, "d_AddComment", 	d_AddComment);
		lua_register(d->ls, "d_AddToDis",		d_AddToDis);
		lua_register(d->ls, "d_AddToDisTab",	d_AddToDisTab);
		lua_register(d->ls, "d_GetByte",		d_GetByte);
		lua_register(d->ls, "d_LookByte",		d_LookByte);
		lua_register(d->ls, "d_DB", 			d_DB);
		lua_register(d->ls, "d_FlushLine",		d_FlushLine);
		lua_register(d->ls, "d_IsCodeByte",		d_IsCodeByte);
		lua_register(d->ls, "d_GetPC",			d_GetPC);
		lua_register(d->ls, "d_LookByteAddr",	d_LookByteAddr);
		lua_register(d->ls, "d_GetPass",		d_GetPass);
		lua_register(d->ls, "d_Message",		d_Message);

/* Register the general support functions */
		lua_register(d->ls, "hex",				d_FromHex);

/* Set up the trap registration functions */
		sprintf(buf,
			"__dz80_pre={}\n"
			"__dz80_post={}\n"
			"function d_PreTrap(op, fn) __dz80_pre[op]=fn d_RegTrap(op, %d) end\n"
			"function d_PostTrap(op, fn) __dz80_post[op]=fn d_RegTrap(op, %d) end\n",
			D_SCRIPT_PRE, D_SCRIPT_POST);

		err = lua_dostring(d->ls, buf);
		if (err)
			return DERR_SCRIPTERROR;
		}

	return DERR_NONE;
}
示例#11
0
文件: ldblib.c 项目: zig/dcplaya
static void hookf (lua_State *L, void *key) {
  lua_getregistry(L);
  lua_pushuserdata(L, key);
  lua_gettable(L, -2);
  if (lua_isfunction(L, -1)) {
    lua_pushvalue(L, 1);
    lua_rawcall(L, 1, 0);
  }
  else
    lua_pop(L, 1);  /* pop result from gettable */
  lua_pop(L, 1);  /* pop table */
}
示例#12
0
static void GetAttribute(void)
{
  char *name = luaL_check_string(2);
  Ihandle* ih = iuplua_checkihandle(1);
  char *value = IupGetAttribute(ih, name);
  if (!value || iupATTRIB_ISINTERNAL(name))
    lua_pushnil();
  else
  {
    if (iupAttribIsPointer(ih, name))
      lua_pushuserdata((void*)value);
    else
      lua_pushstring(value);
  }
}
示例#13
0
static void _wrap_HTMLButtonElementNew(void) {

    Element * _result;
    Document * _arg0;

{
  if (!lua_isnil (lua_getparam (1))) _arg0 = lua_getuserdata (lua_getparam (1));
  else _arg0 = NULL;
}
    _result = (Element *)HTMLButtonElementNew(_arg0);
{
  if (_result != NULL) lua_pushuserdata (_result);
  else lua_pushnil ();
}
    
}
示例#14
0
文件: ldblib.c 项目: zig/dcplaya
static void sethook (lua_State *L, void *key, lua_Hook hook,
                     lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) {
  lua_settop(L, 1);
  if (lua_isnil(L, 1))
    (*sethookf)(L, NULL);
  else if (lua_isfunction(L, 1))
    (*sethookf)(L, hook);
  else
    luaL_argerror(L, 1, "function expected");
  lua_getregistry(L);
  lua_pushuserdata(L, key);
  lua_pushvalue(L, -1);  /* dup key */
  lua_gettable(L, -3);   /* get old value */
  lua_pushvalue(L, -2);  /* key (again) */
  lua_pushvalue(L, 1);
  lua_settable(L, -5);  /* set new value */
}
示例#15
0
/*
** Puts a "Python function" in the Lua stack for later use.
** To Lua, a "Python function" is a table returned by the function
** '_PYTHON.newPythonFunction(PyFuncName, PyFuncHandle)'
*/
static void luaPushPythonFunction(lua_State *L, char *PyFuncName, PyObject *PyFuncHandle) {

   lua_getglobal(L, "_PYTHON");
   lua_pushstring(L, "newPythonFunction");
   lua_gettable(L, -2);

   /* remove "_PYTHON" from the stack */
   lua_remove(L, -2);

   /* call '_PYTHON.newPythonFunction(PyFuncName, PyFuncHandle)' */
   lua_pushstring(L, PyFuncName);
   lua_pushuserdata(L, PyFuncHandle);

   /* puts the Python "function" (a Lua table) in the stack */
   lua_call(L, 2, 1);

}
示例#16
0
static void profile_start(lua_State *L) {
    if (PROFILE_INIT)
        return; // already started.
    lua_Object lobj = lua_getparam(L, 1);
    if (lobj > 0) {
        luaL_arg_check(L, lua_isnumber(L, lobj), 1,
                       "Inform the minimum time results in float");
        PROFILE_RECORD_TIME = (float) lua_getnumber(L, lobj);
    }
    Meta **meta = (Meta **) malloc(MEM_BLOCKSIZE * sizeof(Meta **));

    lua_pushuserdata(L, meta);
    META_REF = lua_ref(L, 1);

    lua_setcallhook(L, callhook);
    PROFILE_START_TIME = clock();
    PROFILE_INIT = true;
}
示例#17
0
static int passresults (lua_State *L, int status, int oldtop) {
  static const char *const errornames[] =
    {"ok", "run-time error", "file error", "syntax error",
     "memory error", "error in error handling"};
  if (status == 0) {
    int nresults = lua_gettop(L) - oldtop;
    if (nresults > 0)
      return nresults;  /* results are already on the stack */
    else {
      lua_pushuserdata(L, NULL);  /* at least one result to signal no errors */
      return 1;
    }
  }
  else {  /* error */
    lua_pushnil(L);
    lua_pushstring(L, errornames[status]);  /* error code */
    return 2;
  }
}
示例#18
0
void lua_pushelement ( lua_State* luaVM, CElement* pElement )
{
    if ( pElement )
    {
        ElementID ID = pElement->GetID ();
        if ( ID != INVALID_ELEMENT_ID )
        {
#pragma message( "Assigned to: lil_Toady" )
    #if REMOVE_WHEN_FIXED
            lua_pushuserdata ( luaVM, "Element", (void*) reinterpret_cast<unsigned int *>(ID.Value()) );
    #else
            lua_pushlightuserdata ( luaVM, (void*) reinterpret_cast<unsigned int *>(ID.Value()) );
    #endif
            return;
        }
    }

    lua_pushnil ( luaVM );
}
示例#19
0
void L1_new_dofile() {
	const char *fname_str = luaL_check_string(1);
	if (g_grim->bundle_dofile(fname_str) == 0)
		if (luaA_passresults() == 0)
			lua_pushuserdata(0);
}
示例#20
0
static void register_getargs (char *argv[]) {
  lua_pushuserdata(L, argv);
  lua_pushcclosure(L, l_getargs, 1);
  lua_setglobal(L, "getargs");
}
示例#21
0
void luaCompat_pushPointer(lua_State* L, void *pointer)
{ /* lua4 */
  lua_pushuserdata(L, pointer);
}
示例#22
0
/*
** Used to put in the Lua stack the elements of a Python tuple.
** This function could be used to pass to Lua the parameters passed
** to a Python function, if calling Lua functions directly from Python
** was implemented, but now it is only used to pass to Lua the returns
** of a Python function.
** If a Python function returns a single value or a tuple, it is passed
** as parameters to Lua. Ony other combination of tuples is not yet implemented.
*/
static BOOLEAN pythonValues_to_luaStack(lua_State *L, PyObject *value, int *_size) {
int n;
int size;
PyObject *tuple;
PyObject *item;
VALUE_TYPES type;
BOOLEAN succeed;

   tuple = pyTryTuple(value);
   size = PyTuple_Size(tuple);

   if (_size) {
      *_size = size;
   }

   succeed = (size > 0)?True:False;

   /* values: Python --> Lua */
   for (n = 0; n < size; n++) {
      item = PyTuple_GetItem(tuple, n);
      type = pyGetType(item);

      switch (type) {

         case (Nothing):
            lua_pushnil(L);
            break;

         case (Number):
            if (PyInt_Check(item)) {
               lua_pushnumber(L, PyInt_AsLong(item));
            } else if (PyFloat_Check(item)) {
               lua_pushnumber(L, PyFloat_AsDouble(item));
            } else {
               lua_pushnil(L);
               PyErr_SetString(PyExc_Exception, "LuaPy: Unknown number type");
               succeed = False;
            }
            break;

         case (String):
            lua_pushstring(L, PyString_AS_STRING(item));
            break;

         case (Function):
            /* ** FALTA IMPLEMENTAR O DECREF CORRESPONDENTE NO GC DE LUA! ** */
            Py_INCREF(item);
            luaPushPythonFunction(L, "unnamed Python function", item);
            break;

         case (Pointer):
            /* ** FALTA IMPLEMENTAR O DECREF CORRESPONDENTE NO GC DE LUA! ** */
            Py_INCREF(item);
            lua_pushuserdata(L, PyCObject_AsVoidPtr(item));
            break;

         case (Container):
            lua_pushnil(L);
            PyErr_SetString(PyExc_Exception, "LuaPy: passing Python tuples to Lua (as a table) is not implemented. Sorry.");
            succeed = False;
            break;

         default:
            lua_pushnil(L);
            PyErr_SetString(PyExc_Exception, "LuaPy: can't translate an unknown type of parameter or return value from Python to Lua");
            succeed = False;
      }

   }

   return succeed;
}
示例#23
0
void (lua_pushuserdata) (void *u) { lua_pushuserdata(u); }
示例#24
0
void kgmLuaPush(void* arg){
  lua_pushuserdata(lua_main, arg);
}
示例#25
0
void kgmLuaScript::push(void* arg)
{
  lua_pushuserdata(handler, arg);
}
示例#26
0
static void luaB_dofile (void) {
  char *fname = luaL_opt_string(1, NULL);
  if (lua_dofile(fname) == 0)
    if (luaA_passresults() == 0)
      lua_pushuserdata(NULL);  /* at least one result to signal no errors */
}
示例#27
0
/* CALL FUNCTION HOOK */
static void callhook(lua_State *L, lua_Function func, char *file, int line) {
    check_start(L);
    Meta **array = get_metadata_array(L);
    if (!array) return; // check if exists (call profile_stop ?)

    if (STACK_INDEX > MEM_BLOCKSIZE - 1) {
        // Reached memory limit, relocated to double.
        int blocksize = MEM_BLOCKSIZE * 2;

        array = realloc(array, blocksize * sizeof(Meta **));

        if (array) {
            lua_unref(L, META_REF); // Remove the old reference (new block of memory).
            lua_pushuserdata(L, array); // Saves the new reference.
            META_REF = lua_ref(L, 1);
            MEM_BLOCKSIZE = blocksize; // Updates the size of the memory block.
        } else {
            lua_error(L, "profiler: out of memory!");
            return; // suppress inspect
        }
    }

    char *func_name;
    char *func_scope;

    if (lua_isfunction(L, func)) {
        func_scope = lua_getobjname(L, func, &func_name);
        Meta *meta = (Meta *) malloc(sizeof(Meta));

        meta->fun_name = func_name ? func_name : "unnamed";
        if (func_scope && strlen(func_scope) > 0) {
            meta->fun_scope = func_scope;
        } else {
            meta->fun_scope = "unknown";
        }
        meta->func_file = file ? file : "unnamed";
        meta->stack_level = STACK_SIZE;
        meta->line = line;

        Children *children = (Children *) malloc(sizeof(Children));
        meta->children = children;
        children->index = 0;
        children->list = NULL;
        children->size = 20;

        Measure *measure = (Measure *) malloc(sizeof(Measure));
        measure->begin = clock();
        meta->measure = measure;

        stack_record.meta = meta;
        push(&stack, stack_record);

        if (STACK_SIZE == 0) {
            array[STACK_INDEX] = meta;
            STACK_INDEX++;
        }
        STACK_SIZE++;

    } else if (STACK_SIZE > 0) {
        STACK_RECORD top_record = pop(&stack);
        STACK_RECORD *new_record = next(&stack);

        Meta *meta = top_record.meta;
        meta->measure->end = clock();
        meta->measure->time_spent = calc_time_spent(meta->measure);

        if (new_record != NULL && meta->measure->time_spent >= PROFILE_RECORD_TIME) {
            Meta *_meta = new_record->meta;
            if (!_meta->children->list) { // already allocated ?
                _meta->children->list = (Meta **) malloc(_meta->children->size * sizeof(Meta **));
                if (!_meta->children->list) lua_error(L, "out of memory");
            }
            if (_meta->children->index > _meta->children->size - 1) {
                _meta->children->size *= 2; // more
                _meta->children->list = (Meta **) realloc(_meta->children->list,
                                                          _meta->children->size * sizeof(Meta **));
                if (!_meta->children->list) lua_error(L, "out of memory");
            }
            _meta->children->list[_meta->children->index] = meta;
            _meta->children->index++;
        }
        STACK_SIZE--;
    }
}