1965 ScriptSetInteger('ScreenWidth', cScreenWidth); |
1965 ScriptSetInteger('ScreenWidth', cScreenWidth); |
1966 ScriptCall('onScreenResize'); |
1966 ScriptCall('onScreenResize'); |
1967 end; |
1967 end; |
1968 |
1968 |
1969 // custom script loader via physfs, passed to lua_load |
1969 // custom script loader via physfs, passed to lua_load |
1970 const BUFSIZE = 16; |
1970 const BUFSIZE = 1024; |
1971 var phyfsReaderBuffer: pointer; |
1971 var physfsReaderBuffer: pointer; external; |
1972 |
1972 function physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external; |
1973 function physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; |
|
1974 var fileSize: Longword; |
|
1975 begin |
|
1976 writeln(stdout, '==== reading'); |
|
1977 if pfsEOF(f) then |
|
1978 physfsReader:= nil |
|
1979 else |
|
1980 begin |
|
1981 sz^:= pfsBlockRead(f, phyfsReaderBuffer, BUFSIZE); |
|
1982 writeln(stdout, '==== read ' + inttostr(sz^)); |
|
1983 if sz^ = 0 then |
|
1984 physfsReader:= nil |
|
1985 else |
|
1986 physfsReader:= phyfsReaderBuffer |
|
1987 end |
|
1988 end; |
|
1989 |
1973 |
1990 |
1974 |
1991 procedure ScriptLoad(name : shortstring); |
1975 procedure ScriptLoad(name : shortstring); |
1992 var ret : LongInt; |
1976 var ret : LongInt; |
1993 s : shortstring; |
1977 s : shortstring; |
1994 f : PFSFile; |
1978 f : PFSFile; |
|
1979 buf : array[0..Pred(BUFSIZE)] of byte; |
1995 begin |
1980 begin |
1996 s:= cPathz[ptData] + name; |
1981 s:= cPathz[ptData] + name; |
1997 if not pfsExists(s) then |
1982 if not pfsExists(s) then |
1998 exit; |
1983 exit; |
1999 |
1984 |
2000 f:= pfsOpenRead(s); |
1985 f:= pfsOpenRead(s); |
2001 if f = nil then |
1986 if f = nil then |
2002 exit; |
1987 exit; |
2003 |
1988 |
2004 GetMem(phyfsReaderBuffer, BUFSIZE); |
1989 physfsReaderBuffer:= @buf; |
2005 ret:= lua_load(luaState, @physfsReader, f, Str2PChar(s)); |
1990 ret:= lua_load(luaState, @physfsReader, f, Str2PChar(s)); |
2006 FreeMem(phyfsReaderBuffer, BUFSIZE); |
|
2007 pfsClose(f); |
1991 pfsClose(f); |
2008 |
1992 |
2009 if ret <> 0 then |
1993 if ret <> 0 then |
2010 begin |
1994 begin |
2011 LuaError('Lua: Failed to load ' + name + '(error ' + IntToStr(ret) + ')'); |
1995 LuaError('Lua: Failed to load ' + name + '(error ' + IntToStr(ret) + ')'); |