about summary refs log blame commit diff stats
path: root/src/ldump.c
blob: c9d3d4870f4d915a46e4f98d88a6af735325647b (plain) (tree)



































































































































































                                                                                 
/*
** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
** save precompiled Lua chunks
** See Copyright Notice in lua.h
*/

#include <stddef.h>

#define ldump_c
#define LUA_CORE

#include "lua.h"

#include "lobject.h"
#include "lstate.h"
#include "lundump.h"

typedef struct {
 lua_State* L;
 lua_Writer writer;
 void* data;
 int strip;
 int status;
} DumpState;

#define DumpMem(b,n,size,D)	DumpBlock(b,(n)*(size),D)
#define DumpVar(x,D)	 	DumpMem(&x,1,sizeof(x),D)

static void DumpBlock(const void* b, size_t size, DumpState* D)
{
 if (D->status==0)
 {
  lua_unlock(D->L);
  D->status=(*D->writer)(D->L,b,size,D->data);
  lua_lock(D->L);
 }
}

static void DumpChar(int y, DumpState* D)
{
 char x=(char)y;
 DumpVar(x,D);
}

static void DumpInt(int x, DumpState* D)
{
 DumpVar(x,D);
}

static void DumpNumber(lua_Number x, DumpState* D)
{
 DumpVar(x,D);
}

static void DumpVector(const void* b, int n, size_t size, DumpState* D)
{
 DumpInt(n,D);
 DumpMem(b,n,size,D);
}

static void DumpString(const TString* s, DumpState* D)
{
 if (s==NULL || getstr(s)==NULL)
 {
  size_t size=0;
  DumpVar(size,D);
 }
 else
 {
  size_t size=s->tsv.len+1;		/* include trailing '\0' */
  DumpVar(size,D);
  DumpBlock(getstr(s),size,D);
 }
}

#define DumpCode(f,D)	 DumpVector(f->code,f->sizecode,sizeof(Instruction),D)

static void DumpFunction(const Proto* f, const TString* p, DumpState* D);

static void DumpConstants(const Proto* f, DumpState* D)
{
 int i,n=f->sizek;
 DumpInt(n,D);
 for (i=0; i<n; i++)
 {
  const TValue* o=&f->k[i];
  DumpChar(ttype(o),D);
  switch (ttype(o))
  {
   case LUA_TNIL:
	break;
   case LUA_TBOOLEAN:
	DumpChar(bvalue(o),D);
	break;
   case LUA_TNUMBER:
	DumpNumber(nvalue(o),D);
	break;
   case LUA_TSTRING:
	DumpString(rawtsvalue(o),D);
	break;
   default:
	lua_assert(0);			/* cannot happen */
	break;
  }
 }
 n=f->sizep;
 DumpInt(n,D);
 for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);
}

static void DumpDebug(const Proto* f, DumpState* D)
{
 int i,n;
 n= (D->strip) ? 0 : f->sizelineinfo;
 DumpVector(f->lineinfo,n,sizeof(int),D);
 n= (D->strip) ? 0 : f->sizelocvars;
 DumpInt(n,D);
 for (i=0; i<n; i++)
 {
  DumpString(f->locvars[i].varname,D);
  DumpInt(f->locvars[i].startpc,D);
  DumpInt(f->locvars[i].endpc,D);
 }
 n= (D->strip) ? 0 : f->sizeupvalues;
 DumpInt(n,D);
 for (i=0; i<n; i++) DumpString(f->upvalues[i],D);
}

static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
{
 DumpString((f->source==p || D->strip) ? NULL : f->source,D);
 DumpInt(f->linedefined,D);
 DumpInt(f->lastlinedefined,D);
 DumpChar(f->nups,D);
 DumpChar(f->numparams,D);
 DumpChar(f->is_vararg,D);
 DumpChar(f->maxstacksize,D);
 DumpCode(f,D);
 DumpConstants(f,D);
 DumpDebug(f,D);
}

static void DumpHeader(DumpState* D)
{
 char h[LUAC_HEADERSIZE];
 luaU_header(h);
 DumpBlock(h,LUAC_HEADERSIZE,D);
}

/*
** dump Lua function as precompiled chunk
*/
int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)
{
 DumpState D;
 D.L=L;
 D.writer=w;
 D.data=data;
 D.strip=strip;
 D.status=0;
 DumpHeader(&D);
 DumpFunction(f,NULL,&D);
 return D.status;
}
n class="nt">dl><dt><a name="Actions-display_file"><strong>display_file</strong></a>(self)</dt></dl> <dl><dt><a name="Actions-display_log"><strong>display_log</strong></a>(self)</dt></dl> <dl><dt><a name="Actions-edit_file"><strong>edit_file</strong></a>(self)</dt><dd><tt>Calls&nbsp;execute_file&nbsp;with&nbsp;the&nbsp;current&nbsp;file&nbsp;and&nbsp;app='editor'</tt></dd></dl> <dl><dt><a name="Actions-enter_bookmark"><strong>enter_bookmark</strong></a>(self, key)</dt><dd><tt>Enter&nbsp;the&nbsp;bookmark&nbsp;with&nbsp;the&nbsp;name&nbsp;&lt;key&gt;</tt></dd></dl> <dl><dt><a name="Actions-enter_dir"><strong>enter_dir</strong></a>(self, path)</dt><dd><tt>Enter&nbsp;the&nbsp;directory&nbsp;at&nbsp;the&nbsp;given&nbsp;path</tt></dd></dl> <dl><dt><a name="Actions-execute_command"><strong>execute_command</strong></a>(self, cmd, **kw)</dt></dl> <dl><dt><a name="Actions-execute_file"><strong>execute_file</strong></a>(self, files, **kw)</dt><dd><tt>Execute&nbsp;a&nbsp;file.<br> app&nbsp;is&nbsp;the&nbsp;name&nbsp;of&nbsp;a&nbsp;method&nbsp;in&nbsp;Applications,&nbsp;without&nbsp;the&nbsp;"app_"<br> flags&nbsp;is&nbsp;a&nbsp;string&nbsp;consisting&nbsp;of&nbsp;applications.ALLOWED_FLAGS<br> mode&nbsp;is&nbsp;a&nbsp;positive&nbsp;integer.<br> Both&nbsp;flags&nbsp;and&nbsp;mode&nbsp;specify&nbsp;how&nbsp;the&nbsp;program&nbsp;is&nbsp;run.</tt></dd></dl> <dl><dt><a name="Actions-exit"><strong>exit</strong></a>(self)</dt><dd><tt>Exit&nbsp;the&nbsp;program</tt></dd></dl> <dl><dt><a name="Actions-force_load_preview"><strong>force_load_preview</strong></a>(self)</dt></dl> <dl><dt><a name="Actions-handle_mouse"><strong>handle_mouse</strong></a>(self)</dt><dd><tt>Handle&nbsp;mouse-buttons&nbsp;if&nbsp;one&nbsp;was&nbsp;pressed</tt></dd></dl> <dl><dt><a name="Actions-history_go"><strong>history_go</strong></a>(self, relative)</dt><dd><tt>Move&nbsp;back&nbsp;and&nbsp;forth&nbsp;in&nbsp;the&nbsp;history</tt></dd></dl> <dl><dt><a name="Actions-interrupt"><strong>interrupt</strong></a>(self)</dt><dd><tt>Waits&nbsp;a&nbsp;short&nbsp;time.<br> If&nbsp;CTRL+C&nbsp;is&nbsp;pressed&nbsp;while&nbsp;waiting,&nbsp;the&nbsp;program&nbsp;will&nbsp;be&nbsp;exited.</tt></dd></dl> <dl><dt><a name="Actions-mark"><strong>mark</strong></a>(self, all<font color="#909090">=False</font>, toggle<font color="#909090">=False</font>, val<font color="#909090">=None</font>, movedown<font color="#909090">=None</font>)</dt><dd><tt>A&nbsp;wrapper&nbsp;for&nbsp;the&nbsp;directory.mark_xyz&nbsp;functions.<br> &nbsp;<br> Arguments:<br> all&nbsp;-&nbsp;change&nbsp;all&nbsp;files&nbsp;of&nbsp;the&nbsp;current&nbsp;directory&nbsp;at&nbsp;once?<br> toggle&nbsp;-&nbsp;toggle&nbsp;the&nbsp;marked-status?<br> val&nbsp;-&nbsp;mark&nbsp;or&nbsp;unmark?</tt></dd></dl> <dl><dt><a name="Actions-mkdir"><strong>mkdir</strong></a>(self, name)</dt></dl> <dl><dt><a name="Actions-move_left"><strong>move_left</strong></a>(self, n<font color="#909090">=1</font>)</dt><dd><tt>Enter&nbsp;the&nbsp;parent&nbsp;directory</tt></dd></dl> <dl><dt><a name="Actions-move_pointer"><strong>move_pointer</strong></a>(self, relative<font color="#909090">=0</font>, absolute<font color="#909090">=None</font>)</dt><dd><tt>Move&nbsp;the&nbsp;pointer&nbsp;down&nbsp;by&nbsp;&lt;relative&gt;&nbsp;or&nbsp;to&nbsp;&lt;absolute&gt;</tt></dd></dl> <dl><dt><a name="Actions-move_pointer_by_pages"><strong>move_pointer_by_pages</strong></a>(self, relative)</dt><dd><tt>Move&nbsp;the&nbsp;pointer&nbsp;down&nbsp;by&nbsp;&lt;relative&gt;&nbsp;pages</tt></dd></dl> <dl><dt><a name="Actions-move_pointer_by_percentage"><strong>move_pointer_by_percentage</strong></a>(self, relative<font color="#909090">=0</font>, absolute<font color="#909090">=None</font>)</dt><dd><tt>Move&nbsp;the&nbsp;pointer&nbsp;down&nbsp;by&nbsp;&lt;relative&gt;%&nbsp;or&nbsp;to&nbsp;&lt;absolute&gt;%</tt></dd></dl> <dl><dt><a name="Actions-move_right"><strong>move_right</strong></a>(self, mode<font color="#909090">=0</font>)</dt><dd><tt>Enter&nbsp;the&nbsp;current&nbsp;directory&nbsp;or&nbsp;execute&nbsp;the&nbsp;current&nbsp;file</tt></dd></dl> <dl><dt><a name="Actions-notify"><strong>notify</strong></a>(self, text, duration<font color="#909090">=4</font>, bad<font color="#909090">=False</font>)</dt></dl> <dl><dt><a name="Actions-open_console"><strong>open_console</strong></a>(self, mode<font color="#909090">=':'</font>, string<font color="#909090">=''</font>)</dt><dd><tt>Open&nbsp;the&nbsp;console&nbsp;if&nbsp;the&nbsp;current&nbsp;UI&nbsp;supports&nbsp;that</tt></dd></dl> <dl><dt><a name="Actions-paste"><strong>paste</strong></a>(self)</dt><dd><tt>Paste&nbsp;the&nbsp;selected&nbsp;items&nbsp;into&nbsp;the&nbsp;current&nbsp;directory</tt></dd></dl> <dl><dt><a name="Actions-redraw_window"><strong>redraw_window</strong></a>(self)</dt><dd><tt>Redraw&nbsp;the&nbsp;window</tt></dd></dl> <dl><dt><a name="Actions-rename"><strong>rename</strong></a>(self, src, dest)</dt></dl> <dl><dt><a name="Actions-reset"><strong>reset</strong></a>(self)</dt><dd><tt>Reset&nbsp;the&nbsp;filemanager,&nbsp;clearing&nbsp;the&nbsp;directory&nbsp;buffer</tt></dd></dl> <dl><dt><a name="Actions-resize"><strong>resize</strong></a>(self)</dt><dd><tt>Update&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;UI</tt></dd></dl> <dl><dt><a name="Actions-scroll"><strong>scroll</strong></a>(self, relative)</dt><dd><tt>Scroll&nbsp;down&nbsp;by&nbsp;&lt;relative&gt;&nbsp;lines</tt></dd></dl> <dl><dt><a name="Actions-search"><strong>search</strong></a>(self, order<font color="#909090">=None</font>, forward<font color="#909090">=True</font>)</dt></dl> <dl><dt><a name="Actions-set_bookmark"><strong>set_bookmark</strong></a>(self, key)</dt><dd><tt>Set&nbsp;the&nbsp;bookmark&nbsp;with&nbsp;the&nbsp;name&nbsp;&lt;key&gt;&nbsp;to&nbsp;the&nbsp;current&nbsp;directory</tt></dd></dl> <dl><dt><a name="Actions-set_filter"><strong>set_filter</strong></a>(self, fltr)</dt></dl> <dl><dt><a name="Actions-set_search_method"><strong>set_search_method</strong></a>(self, order, forward<font color="#909090">=True</font>)</dt></dl> <dl><dt><a name="Actions-sort"><strong>sort</strong></a>(self, func<font color="#909090">=None</font>, reverse<font color="#909090">=None</font>)</dt></dl> <dl><dt><a name="Actions-tag_remove"><strong>tag_remove</strong></a>(self, movedown<font color="#909090">=None</font>)</dt></dl> <dl><dt><a name="Actions-tag_toggle"><strong>tag_toggle</strong></a>(self, movedown<font color="#909090">=None</font>)</dt></dl> <dl><dt><a name="Actions-toggle_boolean_option"><strong>toggle_boolean_option</strong></a>(self, string)</dt><dd><tt>Toggle&nbsp;a&nbsp;boolean&nbsp;option&nbsp;named&nbsp;&lt;string&gt;</tt></dd></dl> <dl><dt><a name="Actions-unset_bookmark"><strong>unset_bookmark</strong></a>(self, key)</dt><dd><tt>Delete&nbsp;the&nbsp;bookmark&nbsp;with&nbsp;the&nbsp;name&nbsp;&lt;key&gt;</tt></dd></dl> <hr> Data and other attributes defined here:<br> <dl><dt><strong>search_forward</strong> = False</dl> <dl><dt><strong>search_method</strong> = 'ctime'</dl> <hr> Data and other attributes inherited from <a href="ranger.shared.html#EnvironmentAware">ranger.shared.EnvironmentAware</a>:<br> <dl><dt><strong>env</strong> = None</dl> <hr> Data descriptors inherited from <a href="ranger.shared.html#Awareness">ranger.shared.Awareness</a>:<br> <dl><dt><strong>__dict__</strong></dt> <dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd> </dl> <dl><dt><strong>__weakref__</strong></dt> <dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd> </dl> <hr> Data and other attributes inherited from <a href="ranger.shared.settings.html#SettingsAware">ranger.shared.settings.SettingsAware</a>:<br> <dl><dt><strong>settings</strong> = &lt;ranger.ext.openstruct.OpenStruct object at 0x7f20a718ad90&gt;</dl> </td></tr></table></td></tr></table> </body></html>