Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eidos/eidos_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ const std::vector<EidosFunctionSignature_CSP> &EidosInterpreter::BuiltInFunction
signatures->emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("fileExists", Eidos_ExecuteFunction_fileExists, kEidosValueMaskLogical | kEidosValueMaskSingleton))->AddString_S(gEidosStr_filePath));
signatures->emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("flushFile", Eidos_ExecuteFunction_flushFile, kEidosValueMaskLogical | kEidosValueMaskSingleton))->AddString_S(gEidosStr_filePath));
signatures->emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("readFile", Eidos_ExecuteFunction_readFile, kEidosValueMaskString))->AddString_S(gEidosStr_filePath));
signatures->emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("readLine", Eidos_ExecuteFunction_readLine, kEidosValueMaskString | kEidosValueMaskSingleton)));
signatures->emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("setwd", Eidos_ExecuteFunction_setwd, kEidosValueMaskString | kEidosValueMaskSingleton))->AddString_S("path"));
signatures->emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("tempdir", Eidos_ExecuteFunction_tempdir, kEidosValueMaskString | kEidosValueMaskSingleton)));
signatures->emplace_back((EidosFunctionSignature *)(new EidosFunctionSignature("writeFile", Eidos_ExecuteFunction_writeFile, kEidosValueMaskLogical | kEidosValueMaskSingleton))->AddString_S(gEidosStr_filePath)->AddString("contents")->AddLogical_OS("append", gStaticEidosValue_LogicalF)->AddLogical_OS("compress", gStaticEidosValue_LogicalF));
Expand Down
1 change: 1 addition & 0 deletions eidos/eidos_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ EidosValue_SP Eidos_ExecuteFunction_filesAtPath(const std::vector<EidosValue_SP>
EidosValue_SP Eidos_ExecuteFunction_flushFile(const std::vector<EidosValue_SP> &p_arguments, EidosInterpreter &p_interpreter);
EidosValue_SP Eidos_ExecuteFunction_getwd(const std::vector<EidosValue_SP> &p_arguments, EidosInterpreter &p_interpreter);
EidosValue_SP Eidos_ExecuteFunction_readFile(const std::vector<EidosValue_SP> &p_arguments, EidosInterpreter &p_interpreter);
EidosValue_SP Eidos_ExecuteFunction_readLine(const std::vector<EidosValue_SP> &p_arguments, EidosInterpreter &p_interpreter);
EidosValue_SP Eidos_ExecuteFunction_setwd(const std::vector<EidosValue_SP> &p_arguments, EidosInterpreter &p_interpreter);
EidosValue_SP Eidos_ExecuteFunction_tempdir(const std::vector<EidosValue_SP> &p_arguments, EidosInterpreter &p_interpreter);
EidosValue_SP Eidos_ExecuteFunction_writeFile(const std::vector<EidosValue_SP> &p_arguments, EidosInterpreter &p_interpreter);
Expand Down
36 changes: 36 additions & 0 deletions eidos/eidos_functions_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include <stdio.h>
#include <dirent.h>
#include <fstream>
#include <iostream>
#include <sys/stat.h>
#include <unistd.h>

#include "../eidos_zlib/zlib.h"

Expand Down Expand Up @@ -220,6 +222,40 @@ EidosValue_SP Eidos_ExecuteFunction_readFile(const std::vector<EidosValue_SP> &p
return result_SP;
}

// (string$)readLine(void)
EidosValue_SP Eidos_ExecuteFunction_readLine(const std::vector<EidosValue_SP> &p_arguments, EidosInterpreter &p_interpreter)
{
#pragma unused (p_arguments)

#ifdef EIDOS_GUI
EIDOS_TERMINATION << "ERROR (Eidos_ExecuteFunction_readLine): function readLine() is not available in GUI environments (SLiMgui, SLiMguiLegacy, or EidosScribe)." << EidosTerminate(nullptr);
#endif

// This function was implemented by Chris Talbot 11/19/25 for use in reinforcement learning environments.
// Associated with issue #576.

EidosValue_SP result_SP(nullptr);

// Read a single line from stdin (command-line mode with interactive terminal)
std::string line;

if (std::getline(std::cin, line))
{
// Control for CRLF vs. LF line endings
if (!line.empty() && line[line.size() - 1] == '\r')
line.pop_back();

result_SP = EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_String(line));
}
else
{
// EOF or error reading from stdin; return empty string
result_SP = EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_String(""));
}

return result_SP;
}

// (string$)setwd(string$ path)
EidosValue_SP Eidos_ExecuteFunction_setwd(const std::vector<EidosValue_SP> &p_arguments, __attribute__((unused)) EidosInterpreter &p_interpreter)
{
Expand Down
Loading