Ticket #5 (new enhancement)

Opened 7 years ago

Last modified 5 years ago

NSOFファイルの直接実行

Reported by: gnue Owned by: gnue
Priority: high Milestone: milestone1
Component: newt Version:
Severity: normal Keywords:
Cc:

Description

NSOFファイルを直接実行する機能。

例:$ newt foo.nsof

Change History

comment:1 Changed 7 years ago by gnue

  • Keywords NSOF removed

comment:2 Changed 7 years ago by gnue

  • Version 0.1.1 deleted

comment:3 Changed 6 years ago by pguyot@…

NSOFにコードありません。オブジェクトあります。

nsof-execute.newt
#!newt

Require("protoFILE");

// This function gets the size of a file using ftell(3)
// It takes an open file (based on protoFILE).
DefGlobalFn('GetFileSizeUsingTell, func (file)
begin
	local pos := file:tell();
	file:seek(0, 'seek_end);
	local size := file:tell();
	file:seek(pos, 'set);
	return size;
end );

// Iterate on each file in the command line and loads them up as NSOF.
// If they are a function, call the function.
foreach path in _ARGV_ do
begin
	// Open the file.
	file := {_proto: @protoFILE};
	file:open(path, "r");
	local size := GetFileSizeUsingTell(file);
	local binary := file:read(size);
	file:close();
	local function := ReadNSOF(binary);
	if (IsFunction(function)) then
		call function with ();
end;

true;
nsof-compile.newt
#!newt

Require("protoFILE");

// This function gets the size of a file using ftell(3)
// It takes an open file (based on protoFILE).
DefGlobalFn('GetFileSizeUsingTell, func (file)
begin
	local pos := file:tell();
	file:seek(0, 'seek_end);
	local size := file:tell();
	file:seek(pos, 'set);
	return size;
end );

// Iterate on each file in the command line and loads them up as text,
// compile them and generate NSOF files with nsof suffix.
foreach path in _ARGV_ do
begin
	// Open the file.
	file := {_proto: @protoFILE};
	file:open(path, "r");
	local size := GetFileSizeUsingTell(file);
	local text := file:read(size);
	file:close();
	local function := Compile(text); // <-- 問題あります。
	// Write the function in NSOF format.
	
	local file := {_proto: @protoFILE};
	file:open(path & ".nsof", "w");
	local binary := MakeNSOF(function, 2);
	file:write(binary);
	file:close();
end;

true;
Note: See TracTickets for help on using tickets.