src/squirrel_std.cpp
branchnoai
changeset 10649 9034b80fdbdb
parent 9727 a5fdea13a991
child 10938 df6235dd2b7a
equal deleted inserted replaced
10648:1ebb27f31a71 10649:9034b80fdbdb
     1 
     1 
     2 #include <squirrel.h>
     2 #include <squirrel.h>
     3 #include <sqstdio.h>
       
     4 #include "stdafx.h"
     3 #include "stdafx.h"
     5 #include "debug.h"
     4 #include "debug.h"
     6 #include "squirrel.hpp"
     5 #include "squirrel.hpp"
     7 #include "squirrel_std.hpp"
     6 #include "squirrel_std.hpp"
     8 #include "core/alloc_func.hpp"
     7 #include "core/alloc_func.hpp"
    45 	/* And now we concat, so we are relative from the current script
    44 	/* And now we concat, so we are relative from the current script
    46 	 * First, we have to make sure we have enough space for the full path */
    45 	 * First, we have to make sure we have enough space for the full path */
    47 	real_filename = ReallocT(real_filename, scstrlen(real_filename) + scstrlen(filename) + 1);
    46 	real_filename = ReallocT(real_filename, scstrlen(real_filename) + scstrlen(filename) + 1);
    48 	scstrcat(real_filename, filename);
    47 	scstrcat(real_filename, filename);
    49 
    48 
    50 	/* Make sure we are in the root-table, so everything is included in the root-level */
    49 	bool ret = Squirrel::LoadScript(vm, FS2OTTD(real_filename));
    51 	sq_pushroottable(vm);
       
    52 
    50 
    53 	SQInteger ret = 0;
       
    54 
       
    55 	/* Compile and load the file */
       
    56 	if (!SQ_SUCCEEDED(sqstd_dofile(vm, real_filename, SQFalse, SQTrue))) {
       
    57 		DEBUG(misc, 0, "[squirrel] Failed to compile '%s'", filename);
       
    58 		ret = SQ_ERROR;
       
    59 	}
       
    60 	/* Reset the top, so the stack stays correct */
    51 	/* Reset the top, so the stack stays correct */
    61 	sq_settop(vm, top);
    52 	sq_settop(vm, top);
    62 	free(real_filename);
    53 	free(real_filename);
    63 
    54 
    64 	return ret;
    55 	return ret ? 0: SQ_ERROR;
    65 }
    56 }
    66 
    57 
    67 void squirrel_register_global_std(Squirrel *engine)
    58 void squirrel_register_global_std(Squirrel *engine)
    68 {
    59 {
    69 	/* We don't use squirrel_helper here, as we want to register to the global
    60 	/* We don't use squirrel_helper here, as we want to register to the global