小编Del*_*ake的帖子

PHP'非对象'错误

我正在使用PHP中的一个小型MVC框架进行练习.但是,PHP似乎不喜欢我的Controller类.该类包含一个加载视图的加载器实例:

abstract class Controller
{
    public $load;
    function __construct($load) 
    {
        $this->load = $load;
    }
    abstract public function index();
}
Run Code Online (Sandbox Code Playgroud)

从那里,我可以覆盖所有控制器的控制器.对于instace,我的索引控制器:

class Index extends Controller
{
    public function index()
    {
        $this->load->view("hello_world");
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我创建它时:

require 'Controller.php';
require 'Load.php'
require 'controllers/Index.php';
$i = new Index(new Load());
$i->index();
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

PHP Fatal error:  Call to a member function view() on a non-object in /var/www/controllers/Index.php on line 7
Run Code Online (Sandbox Code Playgroud)

你能帮助我吗?我知道我在构造函数中设置了load,而load类确实有一个名为view的方法,那为什么它会给我这个错误呢?另外:加载等级,只是为了好的措施

class Load
{
    public function view($filename, $data = null)
    {
        if(is_array($data)) extract($data); …
Run Code Online (Sandbox Code Playgroud)

php

4
推荐指数
1
解决办法
6534
查看次数

从lua 5.2调用ac函数会生成语法错误

我一直在努力让lua脚本为我正在进行的小游戏工作,但是lua似乎比它的价值更麻烦.经过大量的谷歌搜索和头发撕裂,我设法让简单的脚本运行,但很快就碰壁了.C函数似乎不想绑定到lua,或者至少不想在绑定后运行.g ++编译c代码而不会发生意外,但lua解释器会生成此语法错误:

LUA ERROR: bin/lua/main.lua:1: syntax error near 'getVersion'
Run Code Online (Sandbox Code Playgroud)

我的C(++)代码:

#include <lua.hpp>

static const luaL_Reg lualibs[] = 
{
    {"base", luaopen_base},
    {"io", luaopen_io},
    {NULL, NULL}
};

void initLua(lua_State* state);
int getVersion(lua_State* state);

int main(int argc, char* argv[])
{
    lua_State* state = luaL_newstate();
    initLua(state);

    lua_register(state, "getVersion", getVersion);

    int status = luaL_loadfile(state, "bin/lua/main.lua");
    if(status == LUA_OK){
        lua_pcall(state, 0, LUA_MULTRET, 0);
    }else{
        fprintf(stderr, "LUA ERROR: %s\n", lua_tostring(state, -1));
        lua_close(state);
        return -1;
    }

    lua_close(state);
    return 0;
}

void initLua(lua_State* state)
{
    const luaL_Reg* lib = …
Run Code Online (Sandbox Code Playgroud)

c c++ lua

4
推荐指数
1
解决办法
455
查看次数

程序忽略了输入

我正在尝试用C++ 编写一个简单的brainfuck解释器.它到目前为止工作得很好,但它忽略了字符输入命令(',').

口译员:

#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;

#define SIZE 30000

void parse(const char* code);

int main(int argc, char* argv[])
{
    ifstream file;
    string line;
    string buffer;
    string filename;

    cout << "Simple BrainFuck interpreter" << '\n';
    cout << "Enter the name of the file to open: ";
    cin >> filename;
    cin.ignore();

    file.open(filename.c_str());
    if(!file.is_open())
    {
        cout << "ERROR opening file " << filename << '\n';
        system("pause");
        return -1;
    }
    while (getline(file, line)) buffer += line; …
Run Code Online (Sandbox Code Playgroud)

c++ interpreter input brainfuck

2
推荐指数
1
解决办法
244
查看次数

标签 统计

c++ ×2

brainfuck ×1

c ×1

input ×1

interpreter ×1

lua ×1

php ×1